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: Use when designing how a tool fails for an AI agent: error messages that guide recovery, classifying errors as retryable, permanent, needs-user-input, or needs-auth, confirmation requests for ambiguous input, fuzzy-match thresholds, graceful degradation with partial results, and fallback tools. Trigger phrases: "tool error message", "agent keeps retrying", "agent gives up after an error", "ambiguous match", "which user did it mean", "raw 429", "error handling for agent tools", "recovery guidance".4---56# Tool Error Design78Raw error codes mean nothing to a language model. An agent that receives `429` either9retries in a tight loop or gives up; an agent that receives "Rate limited. Wait 3010seconds, or reduce `batchSize` to 50 and retry" does the right thing. Errors are the11tool's chance to teach. Design them with the same care as the success path.1213## Procedure14151. **Enumerate every way the tool can fail**: bad input, missing prerequisite, not16 found, ambiguous match, upstream unavailable, rate limit, timeout, permission17 denied, missing scope, partial completion.182. **Classify each one** into exactly one class (below). The class tells the agent19 whether to retry, change the call, ask the user, or re-authenticate.203. **Write the recovery text** for each: what went wrong, why, and the exact next call.214. **Decide the ambiguity policy** for any natural-identifier input: thresholds for22 auto-accept, confirm, and reject.235. **Decide the degradation policy** for multi-source or multi-step tools: what is24 returned when part of the work fails.256. **Test by reading the error cold**: could an agent with only the tool description26 and this error message make a better second call? If not, rewrite.2728## Rules with examples2930### Every error carries a class (Error Classification)3132| Class | Meaning | Agent should |33| -------------- | --------------------------------------- | ------------------------- |34| `retryable` | Transient; likely to succeed later | Wait `retryAfter`, retry |35| `permanent` | Will not succeed without a changed call | Change parameters or tool |36| `userInput` | Needs a human decision | Ask the user |37| `authRequired` | Credential or scope missing or expired | Trigger re-auth |3839Use the same class vocabulary in every tool in the set. Map upstream errors onto it40inside the tool; the agent never sees vendor-specific codes. Retryable errors always41carry `retryAfterSeconds`.4243### Every error guides recovery (Recovery Guide)4445Structure, not prose:4647```json48{49 "error": "User not found",50 "class": "permanent",51 "reason": "No user matches \"jon smith\"",52 "recoverySteps": [53 "Call search_users(query=\"jon smith\") to list candidates",54 "Retry with the user's email address instead of a display name"55 ],56 "suggestions": [{ "id": "usr_1", "name": "Jon Smyth", "email": "jon@example.com" }]57}58```5960Include concrete tool names and parameter values, not "check your input". Name61alternative tools when one exists. For a rate limit, say the wait and the size to reduce.6263### Ambiguity returns options, never a guess (Confirmation Request)6465When a natural identifier matches more than one record, do not pick one. Return the66matches with enough detail to distinguish them (name, email, last activity), cap the67list at five to ten, and state the exact call to make for each option:6869```json70{71 "class": "userInput",72 "message": "3 contacts match \"Alex\"",73 "options": [74 { "contactId": "c_1", "name": "Alex Kim", "email": "alex.kim@example.com" },75 { "contactId": "c_2", "name": "Alex Reyes", "email": "areyes@example.com" }76 ],77 "instruction": "Call update_contact(contactId=...) with one of the ids above"78}79```8081Zero matches is a `permanent` error with suggestions, not an empty list that reads as82success.8384### Thresholds decide when to ask (Fuzzy Match Threshold)8586Always confirming is slow; never confirming is dangerous. Pick and document thresholds:8788- Above 90% confidence: auto-accept, and log the match for audit.89- 50% to 90%: return the candidates as a confirmation request.90- Below 50%: reject with a "try a different identifier" recovery step.9192Expose the threshold as a parameter with a safe default when callers need to tune it.93Command tools with irreversible effects should set the auto-accept bar higher than94query tools.9596### Return what worked (Graceful Degradation)9798A tool that aggregates from several sources or performs several steps returns the parts99that succeeded, names the parts that failed, states completeness, and says how to get100the rest:101102```json103{104 "completeness": "partial",105 "crm": { "...": "..." },106 "billing": null,107 "errors": [{ "source": "billing", "class": "retryable", "reason": "upstream 503" }],108 "retryHint": "Call get_unified_profile again in 60 seconds for billing data"109}110```111112Total failure that hides a successful partial result wastes the work already done and113the tokens already spent.114115### Provide an alternative when the primary is down (Fallback Tool)116117For critical capabilities, define a fallback order (`slack` then `email` then `sms`),118either switch transparently and report `channelUsed` and `wasFallback: true`, or return119a `permanent` error that names the fallback tool to call. Never fall back silently on a120command with different side effects than the one requested.121122### Timeouts are errors too123124A timeout returns a `retryable` error that says what timed out, how long the limit is,125whether partial results are attached, and whether an async variant exists. See126`tool-design-execution` for the boundary itself.127128## Anti-patterns129130- Passing the upstream exception string or HTTP status through as the error.131- "Invalid input" with no field name and no valid values.132- Picking the first fuzzy match on a command tool.133- Throwing on the first failed item in a batch.134- A retryable error with no `retryAfter`, so the agent retries immediately.135- Success-shaped responses for failures (`{ "items": [] }` when the query was invalid).136- Recovery text written for the developer ("see logs") rather than the agent.137138## On Runtype139140- An `external` tool's upstream error body is what the model sees unless the tool141 shapes it; map upstream status codes to the four classes in a `custom` tool or in a142 `transform-data` step that follows it.143- **Confirmation requests have a native carrier on chat surfaces.** Behind a Persona144 widget, expose the built-in local tools (`features.askUserQuestion.expose`,145 `features.suggestReplies.expose`) so an ambiguous match becomes a rendered choice146 the user taps, rather than a JSON options blob the model has to narrate. Elsewhere,147 return the options in the tool result as above.148- **Know which steps swallow and which fail** when `errorHandling` is unset:149 `fetch-url`, `api-call`, `crawl`, and `search` continue with `defaultValue`;150 `paginate-api` fails; `upsert-record` and `update-record` report `success: false`151 and write no output when their input contract is not met (missing source, no152 resolvable target), while operation failures still swallow. Set `errorHandling` to153 `"fail"` or `"continue"` explicitly on any step whose swallow would hide a real154 failure from the agent.155- The platform's own pauses are not errors: `await` frames mean "waiting on a human156 or the client" (approval, client tool, elicitation, detached run), and an agent157 surface must render them as such rather than as failures.158- Retryable errors from tools are retried by the model, not the platform, so159 `retryAfterSeconds` in the result is what stops a tight loop.160- Test failure paths with `execute_tool` using deliberately wrong inputs before wiring161 the tool into an agent, and capture real failures as eval cases with162 `add_eval_case_from_execution` so the fix is pinned.