Lesson 12 / 25

Errors That Guide the Model

Return short, specific errors that say what to change.

Errors are instructions

When a call fails, the error text becomes part of the model's next prompt. "Error 500" gives it nothing to work with; "No account with id 99. Valid ids are 1 to 20; call list_accounts to see them" lets it recover in one step. Mark the result as an error (is_error), keep it short, and never include secrets or stack traces.

Show the dispatcher's errors

Look back at the unknown-tool error from the registry example: it lists the available tools. That small addition fixes typos in one retry.

Quick check: Which error message best helps the model recover?

  • "Failed."
  • "No account with id 99. Valid ids: 1-20. Call list_accounts."
  • A full stack trace
  • "Something went wrong"
Answer

"No account with id 99. Valid ids: 1-20. Call list_accounts." — It names the problem, the valid range and the next action.