← Back to patterns
build

Anthropic's Error Message Prompt Engineering Pattern

TRIGGER

Agents were getting stuck or making repeated failed attempts when tools returned standard error responses—seeing 'Error: Invalid parameter' or stack traces, agents couldn't determine what specific change would fix the issue and either gave up or hallucinated solutions.

APPROACH

Anthropic's tool engineering team redesigned error responses by analyzing tool calling metrics and agent transcripts to identify common failure patterns, then rewrote error messages as actionable correction prompts. Input: malformed tool call or constraint violation. Output: message specifying what was wrong and exactly how to fix it. For example, invalid date inputs return "Date must be in ISO format (YYYY-MM-DD). You provided: next tuesday. Try: 2025-01-15." For truncated responses exceeding the 25,000-token limit, they include steering instructions like "Results truncated. Consider using more specific search terms or adding filters." When testing Claude's web search tool, they identified the model needlessly appending "2025" to queries and fixed it by improving the tool description—demonstrating that error pattern analysis directly drives tool improvements.

PATTERN

Your agent will retry the same failing call or give up entirely unless errors tell it exactly what to fix. Error messages are prompts to your agent—"Invalid date format" means nothing without "You provided: next tuesday. Try: 2025-01-15."

WORKS WHEN

  • Error conditions have clear, specific remediation steps the agent can take
  • Evaluation shows agents making repeated similar errors or giving up after tool failures
  • The tool can infer what the agent likely intended from the malformed input
  • Input validation happens before expensive operations, so helpful errors are cheap to generate
  • Common error patterns are identifiable from evaluation transcripts

FAILS WHEN

  • Errors stem from external system failures where no agent action would help
  • The remediation would require domain knowledge the agent doesn't have
  • Generating helpful error messages would require expensive computation or additional API calls
  • Error conditions are rare enough that engineering effort isn't justified
  • Security constraints prevent revealing why an operation failed

Stage

build

From

September 2025

Want patterns like this in your inbox?

3 patterns weekly. No fluff.