When collection fails repeatedly — wrong format, no match in the database, ambiguous input — you need a reliable escalation path. This recipe uses a counter inDocumentation Index
Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
Use this file to discover all available pages before exploring further.
conv.state to enforce a hard retry limit and hand off after N failures.
When to use this
Use this pattern when:- A client SLA specifies maximum retry attempts (e.g., “hand off after 3 failures”)
- The flow collects high-stakes data where LLM-led retries are not predictable enough
- Compliance requires that callers always reach a human if automation fails
The complete pattern
How the counter works
Resetting the counter
Resetconv.state["account_attempts"] to 0 after a successful collection. This matters if the same flow is used for multiple collection steps — you don’t want attempt count from Step 1 bleeding into Step 2.
Separating the utterance from the function
For the handoff message, consider passing the utterance as a parameter so the LLM can generate a contextually appropriate goodbye, while the handoff itself is deterministic:escalate with an appropriate transition message.”
Key decisions
Why use content instead of utterance for re-prompts?
Why use content instead of utterance for re-prompts?
Returning
content lets the LLM re-phrase the request naturally each time. Returning a hard-coded utterance would make every re-prompt sound identical, which feels robotic after the first failure.Why MAX_ATTEMPTS = 3?
Why MAX_ATTEMPTS = 3?
Three attempts is a common SLA default. Adjust to match your client’s requirements. Store it as a constant at the top of the file so it’s easy to find and change.
Why reset the counter on success?
Why reset the counter on success?
If the same validation function is reused in multiple parts of the flow (or if the flow is called again in the same session), you don’t want previous failures counting against new attempts.
Check your understanding
← SMS confirmation
Previous recipe
Caller ID validation →
Next recipe

