Tool Error Design
Raw error codes mean nothing to a language model. An agent that receives 429 either
retries in a tight loop or gives up; an agent that receives "Rate limited. Wait 30
seconds, or reduce batchSize to 50 and retry" does the right thing. Errors are the
tool's chance to teach. Design them with the same care as the success path.
Procedure
- Enumerate every way the tool can fail: bad input, missing prerequisite, not
found, ambiguous match, upstream unavailable, rate limit, timeout, permission
denied, missing scope, partial completion.
- Classify each one into exactly one class (below). The class tells the agent
whether to retry, change the call, ask the user, or re-authenticate.
- Write the recovery text for each: what went wrong, why, and the exact next call.
- Decide the ambiguity policy for any natural-identifier input: thresholds for
auto-accept, confirm, and reject.
- Decide the degradation policy for multi-source or multi-step tools: what is
returned when part of the work fails.
- Test by reading the error cold: could an agent with only the tool description
and this error message make a better second call? If not, rewrite.
Rules with examples
Every error carries a class (Error Classification)
| Class |
Meaning |
Agent should |
retryable |
Transient; likely to succeed later |
Wait retryAfter, retry |
permanent |
Will not succeed without a changed call |
Change parameters or tool |
userInput |
Needs a human decision |
Ask the user |
authRequired |
Credential or scope missing or expired |
Trigger re-auth |
Use the same class vocabulary in every tool in the set. Map upstream errors onto it
inside the tool; the agent never sees vendor-specific codes. Retryable errors always
carry retryAfterSeconds.
Every error guides recovery (Recovery Guide)
Structure, not prose:
{
"error": "User not found",
"class": "permanent",
"reason": "No user matches \"jon smith\"",
"recoverySteps": [
"Call search_users(query=\"jon smith\") to list candidates",
"Retry with the user's email address instead of a display name"
],
"suggestions": [{ "id": "usr_1", "name": "Jon Smyth", "email": "jon@example.com" }]
}
Include concrete tool names and parameter values, not "check your input". Name
alternative tools when one exists. For a rate limit, say the wait and the size to reduce.
Ambiguity returns options, never a guess (Confirmation Request)
When a natural identifier matches more than one record, do not pick one. Return the
matches with enough detail to distinguish them (name, email, last activity), cap the
list at five to ten, and state the exact call to make for each option:
{
"class": "userInput",
"message": "3 contacts match \"Alex\"",
"options": [
{ "contactId": "c_1", "name": "Alex Kim", "email": "alex.kim@example.com" },
{ "contactId": "c_2", "name": "Alex Reyes", "email": "areyes@example.com" }
],
"instruction": "Call update_contact(contactId=...) with one of the ids above"
}
Zero matches is a permanent error with suggestions, not an empty list that reads as
success.
Thresholds decide when to ask (Fuzzy Match Threshold)
Always confirming is slow; never confirming is dangerous. Pick and document thresholds:
- Above 90% confidence: auto-accept, and log the match for audit.
- 50% to 90%: return the candidates as a confirmation request.
- Below 50%: reject with a "try a different identifier" recovery step.
Expose the threshold as a parameter with a safe default when callers need to tune it.
Command tools with irreversible effects should set the auto-accept bar higher than
query tools.
Return what worked (Graceful Degradation)
A tool that aggregates from several sources or performs several steps returns the parts
that succeeded, names the parts that failed, states completeness, and says how to get
the rest:
{
"completeness": "partial",
"crm": { "...": "..." },
"billing": null,
"errors": [{ "source": "billing", "class": "retryable", "reason": "upstream 503" }],
"retryHint": "Call get_unified_profile again in 60 seconds for billing data"
}
Total failure that hides a successful partial result wastes the work already done and
the tokens already spent.
Provide an alternative when the primary is down (Fallback Tool)
For critical capabilities, define a fallback order (slack then email then sms),
either switch transparently and report channelUsed and wasFallback: true, or return
a permanent error that names the fallback tool to call. Never fall back silently on a
command with different side effects than the one requested.
Timeouts are errors too
A timeout returns a retryable error that says what timed out, how long the limit is,
whether partial results are attached, and whether an async variant exists. See
tool-design-execution for the boundary itself.
Anti-patterns
- Passing the upstream exception string or HTTP status through as the error.
- "Invalid input" with no field name and no valid values.
- Picking the first fuzzy match on a command tool.
- Throwing on the first failed item in a batch.
- A retryable error with no
retryAfter, so the agent retries immediately.
- Success-shaped responses for failures (
{ "items": [] } when the query was invalid).
- Recovery text written for the developer ("see logs") rather than the agent.
On Runtype
- An
external tool's upstream error body is what the model sees unless the tool
shapes it; map upstream status codes to the four classes in a custom tool or in a
transform-data step that follows it.
- Confirmation requests have a native carrier on chat surfaces. Behind a Persona
widget, expose the built-in local tools (
features.askUserQuestion.expose,
features.suggestReplies.expose) so an ambiguous match becomes a rendered choice
the user taps, rather than a JSON options blob the model has to narrate. Elsewhere,
return the options in the tool result as above.
- Know which steps swallow and which fail when
errorHandling is unset:
fetch-url, api-call, crawl, and search continue with defaultValue;
paginate-api fails; upsert-record and update-record report success: false
and write no output when their input contract is not met (missing source, no
resolvable target), while operation failures still swallow. Set errorHandling to
"fail" or "continue" explicitly on any step whose swallow would hide a real
failure from the agent.
- The platform's own pauses are not errors:
await frames mean "waiting on a human
or the client" (approval, client tool, elicitation, detached run), and an agent
surface must render them as such rather than as failures.
- Retryable errors from tools are retried by the model, not the platform, so
retryAfterSeconds in the result is what stops a tight loop.
- Test failure paths with
execute_tool using deliberately wrong inputs before wiring
the tool into an agent, and capture real failures as eval cases with
add_eval_case_from_execution so the fix is pinned.
1---2name: tool-design-errors3description: >-4 Use when designing how a tool fails for an AI agent: error messages that guide5 recovery, classifying errors as retryable, permanent, needs-user-input, or6 needs-auth, confirmation requests for ambiguous input, fuzzy-match thresholds,7 graceful degradation with partial results, and fallback tools. Trigger phrases:8 "tool error message", "agent keeps retrying", "agent gives up after an error",9 "ambiguous match", "which user did it mean", "raw 429", "error handling for agent10 tools", "recovery guidance".11user-invocable: true12argument-hint: '[tool whose failure paths to design]'13---1415# Tool Error Design1617Raw error codes mean nothing to a language model. An agent that receives `429` either18retries in a tight loop or gives up; an agent that receives "Rate limited. Wait 3019seconds, or reduce `batchSize` to 50 and retry" does the right thing. Errors are the20tool's chance to teach. Design them with the same care as the success path.2122## Procedure23241. **Enumerate every way the tool can fail**: bad input, missing prerequisite, not25 found, ambiguous match, upstream unavailable, rate limit, timeout, permission26 denied, missing scope, partial completion.272. **Classify each one** into exactly one class (below). The class tells the agent28 whether to retry, change the call, ask the user, or re-authenticate.293. **Write the recovery text** for each: what went wrong, why, and the exact next call.304. **Decide the ambiguity policy** for any natural-identifier input: thresholds for31 auto-accept, confirm, and reject.325. **Decide the degradation policy** for multi-source or multi-step tools: what is33 returned when part of the work fails.346. **Test by reading the error cold**: could an agent with only the tool description35 and this error message make a better second call? If not, rewrite.3637## Rules with examples3839### Every error carries a class (Error Classification)4041| Class | Meaning | Agent should |42| -------------- | --------------------------------------- | ------------------------- |43| `retryable` | Transient; likely to succeed later | Wait `retryAfter`, retry |44| `permanent` | Will not succeed without a changed call | Change parameters or tool |45| `userInput` | Needs a human decision | Ask the user |46| `authRequired` | Credential or scope missing or expired | Trigger re-auth |4748Use the same class vocabulary in every tool in the set. Map upstream errors onto it49inside the tool; the agent never sees vendor-specific codes. Retryable errors always50carry `retryAfterSeconds`.5152### Every error guides recovery (Recovery Guide)5354Structure, not prose:5556```json57{58 "error": "User not found",59 "class": "permanent",60 "reason": "No user matches \"jon smith\"",61 "recoverySteps": [62 "Call search_users(query=\"jon smith\") to list candidates",63 "Retry with the user's email address instead of a display name"64 ],65 "suggestions": [{ "id": "usr_1", "name": "Jon Smyth", "email": "jon@example.com" }]66}67```6869Include concrete tool names and parameter values, not "check your input". Name70alternative tools when one exists. For a rate limit, say the wait and the size to reduce.7172### Ambiguity returns options, never a guess (Confirmation Request)7374When a natural identifier matches more than one record, do not pick one. Return the75matches with enough detail to distinguish them (name, email, last activity), cap the76list at five to ten, and state the exact call to make for each option:7778```json79{80 "class": "userInput",81 "message": "3 contacts match \"Alex\"",82 "options": [83 { "contactId": "c_1", "name": "Alex Kim", "email": "alex.kim@example.com" },84 { "contactId": "c_2", "name": "Alex Reyes", "email": "areyes@example.com" }85 ],86 "instruction": "Call update_contact(contactId=...) with one of the ids above"87}88```8990Zero matches is a `permanent` error with suggestions, not an empty list that reads as91success.9293### Thresholds decide when to ask (Fuzzy Match Threshold)9495Always confirming is slow; never confirming is dangerous. Pick and document thresholds:9697- Above 90% confidence: auto-accept, and log the match for audit.98- 50% to 90%: return the candidates as a confirmation request.99- Below 50%: reject with a "try a different identifier" recovery step.100101Expose the threshold as a parameter with a safe default when callers need to tune it.102Command tools with irreversible effects should set the auto-accept bar higher than103query tools.104105### Return what worked (Graceful Degradation)106107A tool that aggregates from several sources or performs several steps returns the parts108that succeeded, names the parts that failed, states completeness, and says how to get109the rest:110111```json112{113 "completeness": "partial",114 "crm": { "...": "..." },115 "billing": null,116 "errors": [{ "source": "billing", "class": "retryable", "reason": "upstream 503" }],117 "retryHint": "Call get_unified_profile again in 60 seconds for billing data"118}119```120121Total failure that hides a successful partial result wastes the work already done and122the tokens already spent.123124### Provide an alternative when the primary is down (Fallback Tool)125126For critical capabilities, define a fallback order (`slack` then `email` then `sms`),127either switch transparently and report `channelUsed` and `wasFallback: true`, or return128a `permanent` error that names the fallback tool to call. Never fall back silently on a129command with different side effects than the one requested.130131### Timeouts are errors too132133A timeout returns a `retryable` error that says what timed out, how long the limit is,134whether partial results are attached, and whether an async variant exists. See135`tool-design-execution` for the boundary itself.136137## Anti-patterns138139- Passing the upstream exception string or HTTP status through as the error.140- "Invalid input" with no field name and no valid values.141- Picking the first fuzzy match on a command tool.142- Throwing on the first failed item in a batch.143- A retryable error with no `retryAfter`, so the agent retries immediately.144- Success-shaped responses for failures (`{ "items": [] }` when the query was invalid).145- Recovery text written for the developer ("see logs") rather than the agent.146147## On Runtype148149- An `external` tool's upstream error body is what the model sees unless the tool150 shapes it; map upstream status codes to the four classes in a `custom` tool or in a151 `transform-data` step that follows it.152- **Confirmation requests have a native carrier on chat surfaces.** Behind a Persona153 widget, expose the built-in local tools (`features.askUserQuestion.expose`,154 `features.suggestReplies.expose`) so an ambiguous match becomes a rendered choice155 the user taps, rather than a JSON options blob the model has to narrate. Elsewhere,156 return the options in the tool result as above.157- **Know which steps swallow and which fail** when `errorHandling` is unset:158 `fetch-url`, `api-call`, `crawl`, and `search` continue with `defaultValue`;159 `paginate-api` fails; `upsert-record` and `update-record` report `success: false`160 and write no output when their input contract is not met (missing source, no161 resolvable target), while operation failures still swallow. Set `errorHandling` to162 `"fail"` or `"continue"` explicitly on any step whose swallow would hide a real163 failure from the agent.164- The platform's own pauses are not errors: `await` frames mean "waiting on a human165 or the client" (approval, client tool, elicitation, detached run), and an agent166 surface must render them as such rather than as failures.167- Retryable errors from tools are retried by the model, not the platform, so168 `retryAfterSeconds` in the result is what stops a tight loop.169- Test failure paths with `execute_tool` using deliberately wrong inputs before wiring170 the tool into an agent, and capture real failures as eval cases with171 `add_eval_case_from_execution` so the fix is pinned.