Agents, Tool Use & MCP·Question 16 of 90Intermediate

How should tool errors be surfaced to the model?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

As structured, actionable tool results - never as exceptions that kill the loop, and never silently swallowed. An agent's ability to recover from a failed step is what breaks the compounding-error multiplication, and the error message is the recovery interface.

Full worked answer

As structured, actionable tool results - never as exceptions that kill the loop, and never silently swallowed. An agent's ability to recover from a failed step is what breaks the compounding-error multiplication, and the error message is the recovery interface.

Principles:

  • Return the error as the tool result (most APIs have an is_error flag on tool results). The model then sees the failure as an observation and can adapt - retry, change arguments, or pick another approach.
  • Say what to do, not just what happened. Compare: KeyError: 'status' vs Unknown field 'status'. Valid filters: state (open|closed), assignee, label. Example: list_issues(state="open"). The second turns a dead end into a course correction in one iteration; the first often triggers a blind identical retry.
  • Include the key detail, drop the noise. A 40-line stack trace is token waste that buries the one line that matters. For code-execution tools, keep the final error line and the relevant frame.
  • Distinguish retryable from fatal. rate_limited, retry after 30s invites a different response than permission denied: read-only credentials. If the executor knows, tell the model.
  • Suggest near-misses. File 'config.yml' not found. Similar: 'config.yaml' exploits the model's ability to recognise its own typo-level mistakes.
  • Watch for error loops. If the same call fails identically twice, the harness should intervene - inject a message like "you've tried this twice with the same result; try a different approach" - rather than letting the model grind through its iteration budget.

The meta-point: error messages are prompts. Teams tune system prompts obsessively and then return raw errno values from tools; reading production trajectories usually reveals errors, not instructions, as the biggest reliability lever.

What a good answer covers

  • As structured, actionable tool results - never as exceptions that kill the loop, and never silently swallowed
  • An agent's ability to recover from a failed step is what breaks the compounding-error multiplication,…
  • Return the error as the tool result (most APIs have an is_error flag on tool results)
  • Say what to do, not just what happened
  • Include the key detail, drop the noise

Key terms: Distinguish retryable from fatal · Suggest near-misses · Watch for error loops

Interviewer follow-ups to expect

  1. Should transient infrastructure errors (timeouts, 502s) even reach the model, or be retried silently by the executor?

  2. How would you measure whether your error messages are working?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep