Level 3 — Lesson 3 of 5 — Learn common flow patterns for collecting, validating, and acting on user input.
The three patterns
When a flow collects information from a user, there are three distinct operations:Collection
Getting a value you don’t already have. The user provides a phone number, name, or tracking number.
Validation
Checking the format. Is this a valid tracking number? Does it match the expected pattern (e.g., 3 letters followed by 5 digits)?
Verification
Checking against known data. Does this tracking number exist in the system? Does this phone number match the account on file?
Collection pattern
The simplest flow pattern: ask for a value, save it, move on.Validation pattern
After collecting a value, check whether it matches the expected format before using it.Check your understanding
Verification pattern
After validation passes, check the value against your backend.LLM-led vs deterministic control
When something goes wrong in a flow (validation fails, API returns no match), you have two approaches:- LLM-led
- Deterministic
Let the model decide how to handle retries and rephrasing.Pros: Flexible, handles edge cases naturally, less code to write.Cons: Less predictable. The model might retry indefinitely or phrase things inconsistently.
When to use each approach
| Scenario | Approach |
|---|---|
| Low-stakes collection (name, preference) | LLM-led |
| High-stakes collection (account number, payment) | Deterministic |
| Retry limits required by the client | Deterministic |
| Natural rephrasing matters | LLM-led |
| Compliance or audit requirements | Deterministic |
Check your understanding
Handoff from a flow
When the user fails repeatedly or the flow cannot continue, hand off to a live agent.utterance — The message to say to the user before transferring
By passing the utterance as a function argument, the model generates a contextually appropriate goodbye message, but the handoff is handled deterministically.
Design principles
Guide explicitly
Always define what happens after each step. Never assume the model will figure out the next action.
Design for failure
Plan what happens when validation fails, APIs are down, or the user gives unexpected input. The happy path is the easy part.
Keep steps focused
Each step should do one thing: collect one value, confirm one detail, or present one choice.
Balance flexibility and control
Use the model for language tasks. Use code for logic tasks. Combine them for the best results.
Try it yourself
Challenge: Design a tracking number lookup flow
Design a 3-step flow that:
- Collects a tracking number
- Validates the format (3 uppercase letters + 5 digits)
- Looks up the order and reports the status
- What happens if validation fails
- What happens if the order is not found
- A retry limit of 3 attempts before handoff
Hint
Hint
Use
conv.state to store the tracking number and an attempt counter. Each step should have a clear prompt and one flow function. The validation step should check the counter before re-prompting.Example solution
Example solution
Step 1 — CollectPrompt: “Ask the user for their tracking number. Once they provide it, call Step 2 — ValidatePrompt: “The tracking number has been collected. Call Step 3 — LookupPrompt: “The tracking number is validated. Call
save_tracking.”check_format to validate it.”lookup_order to check the status.”
