Skip to content
Claude Certified Architect – Foundations (CCAR-F) Exam Prep

Lesson 9 of 30 · 6 min

x
9/30

Structured Error Responses

Video lesson: CCAR-F 09/30: Structured Error Responses

Principle (design guidance)

A bare "Error" or a stack trace gives the model nothing to act on. Return a structured error with:

  • an error category (for example transient, validation, permission, business-rule, not-found)
  • a retryable flag
  • a human-readable message saying what happened and what to try
  • relevant context (which input was bad, how long to wait)

This lets the model choose: retry (transient), fix the input (validation), escalate (permission or policy), or report honestly (not found).

Mechanics (API behaviour)

  • A tool failure is returned to Claude as a tool_result for the matching tool_use id. The API's tool_result block carries an is_error flag for failures. Keep the rule from 1.1: results only in that user message, one result per tool_use.
  • Handle your own HTTP and tool exceptions in the loop; do not let a tool exception crash the loop.
  • In the Agent SDK, PostToolUseFailure hooks run when a tool fails, which is a place to log or normalise errors.

Access failure vs empty result (design guidance)

These are different and must not look alike:

SituationWrong signalRight signal
Database timed outEmpty list []Error: category transient, retryable true
Caller lacks permission"No results"Error: category permission, not retryable
Query ran and nothing matchedErrorSuccess with an empty result

Returning an empty success for a failure causes confident wrong answers ("no matching orders found") and silent data loss.

Retries and loops

  • Retry transient errors with a bounded count and backoff.
  • Do not retry validation or permission errors unchanged.
  • Bound the whole loop (see 1.1).

Exam traps

  • Generic "operation failed" messages.
  • Empty result for a timeout.
  • Retrying everything the same way.
  • Swallowing a tool error so the agent proceeds as if it worked (see 5.3 Error propagation).

References

  1. Define tools — checked Oct 16, 2026
  2. Hooks in the SDK — checked Oct 16, 2026

Check your understanding

  • A lookup times out. Return an empty list or an error?Show answer

    Answer

    An error, marked transient/retryable.
  • Which field tells the model whether to try again?Show answer

    Answer

    The retryable flag, with the category.
  • A valid query finds no rows. Error?Show answer

    Answer

    No; a successful empty result.
Previous

Progress is saved in this browser.

Next Lesson