Tools fail. The model has to know what to do.
When a tool returns an error, the model receives the error as a tool_result and decides what to do. Without guidance, the model often retries the same call (especially on transient errors), gives up too early, or invents data to fill in for the failed result. Each behavior is a bug; each is fixable in the prompt.
Error-shape conventions
Return errors as structured JSON the model can read: {"error": "<code>", "message": "<text>", "retry": true|false, "hint": "<what to try>"}. This gives the model both a parseable signal and a human-readable hint.
Prompt instructions for error recovery
- If a tool returns
retry: true, retry once with the same arguments. - If a tool returns
retry: false, try a different approach or escalate. - If a tool returns 'not found,' do not invent data; tell the user the lookup failed.
- If a tool errors twice, stop and surface the failure.