Skip to content

Diagnose a failure from its trace

Find the line in a log or trace that explains a failure, name its origin (request, credentials, limit, server, model output or your own integration code), and pick the recovery that fits.

Scenario

At 03:00 the on-call engineer for a ticket-summary service is paged: 6% of summaries failed overnight. The dashboard groups them as "Claude errors".

The trace tells a different story. Half are 529 overloaded_error responses that a retry would have fixed. The other half are HTTP 200 responses whose JSON the service couldn't parse. Two causes, two fixes, one misleading label.

Explanation

Step 1: did the request fail, or did it succeed?

  • An error is an HTTP 4xx or 5xx. The body has an error object with a type, plus a request_id to quote to support.
  • A successful response is HTTP 200 with a stop_reason. If something is still wrong, the cause is in the output or in how your code handled it.
  • With streaming, an error can arrive after the 200, as an error event in the stream (for example overloaded_error). Code that only checks the status saves a partial answer.

Step 2: classify the origin, because it decides the recovery.

Origin Signals Recovery
Your request 400 invalid_request_error, 413 request_too_large, 404 Fix the request; a retry fails identically
Credentials, account 401 authentication_error, 403 permission_error, 402 billing_error Fix the key, access or billing
Limit 429 rate_limit_error Wait for retry-after, then retry; reduce load. No retry-after and it never clears: the usage tier's monthly spend cap, so stop retrying and alert a person
Server, transport 500 api_error, 529 overloaded_error, 504 timeout_error Retry with exponential backoff; stream long requests
Model output 200 with max_tokens, refusal, model_context_window_exceeded max_tokens: raise it or continue. refusal: read stop_details. Context window: treat as truncated

The official SDKs already retry connection errors, 408, 409, 429 and 5xx errors with backoff (twice by default) and honour retry-after. Your own retry layer must not undo that.

Step 3: integration or model? When a 200 response looks wrong, compare three things in the trace:

  1. What was sent. Did the request hold the data the answer needed? If retrieval, truncation or a template dropped it, the fault is in your code, however wrong the answer looks.
  2. What came back. Read the raw response, not what the UI showed. Check stop_reason before blaming the content.
  3. What the user saw. If the raw response was right and the screen wasn't, the fault is in parsing or rendering.

Only when the input was right and the raw output was still wrong is it a prompt or model problem, and then the fix is an eval, not a retry.

Worked example

A legal-ops tool answers questions about uploaded contracts. A user reports: "It says the contract has no termination clause. It does, in section 14."

First reaction: "The model hallucinated. Add 'read carefully' to the prompt."

Reading the trace instead:

10:41:07 upload contract_8812.pdf (61 pages)
10:41:08 extracted 148,220 chars
10:41:08 prompt built: doc truncated to 60,000 chars
10:41:12 req_01F... 200 stop_reason=end_turn
10:41:12 answer: "No termination clause found."

The response finished normally, and given the 60,000 characters it received, "no termination clause" was a fair answer: section 14 was cut off before the request was sent. The fault is the truncation line, in the integration layer. The fix is to stop truncating silently: send the whole document if it fits, or retrieve the relevant sections. A prompt change would not have helped, because the model never saw section 14.