Fallback handling
Real users type things your router never planned for. "How long have you been open?" "Is my doctor available on weekends?" "Thanks!" Without a fallback node these messages either crash the flow or get force-routed into the booking branch and produce nonsense. The smalltalk node is your escape hatch.
async def smalltalk(state: BookingState) -> BookingState:
intent = state.get("intent") or "unknown"
system = (
"You are a friendly healthcare booking assistant. "
"Keep replies to 1-2 sentences."
)
prompt = (
f"The patient's intent was classified as '{intent}'. "
f"Message: {state.get('user_message', '')}\n"
"Reply helpfully. If they want to book, invite them to describe their symptom."
)
state["assistant_reply"] = await _llm_text(prompt, system)
state["status"] = state.get("status") or "gathering"
_record_event(state, "smalltalk", {})
return stateThe fallback node takes any non-booking intent and produces a short, helpful reply. It nudges the user toward the happy path (describe a symptom) without locking them out. The status stays in gathering so the next turn starts fresh.
Ordering exercise: Order what happens when intent = unknown
Loading practice…
Quiz: Quiz
Loading practice…
Checkpoint: Intent routing checkpoint
Loading practice…