Eval, Testing, and Debugging
Failure-Mode Diagnosis
Exam objective: Analyzing a trace excerpt or reproduction to identify the failure mode, such as hallucination, refusal, under-acting, context loss, format drift, or inconsistent output; isolating whether it originates in the integration layer or in model output; and selecting a recovery that addresses the cause rather than the symptom.
What the exam tests
You get a trace, log or reproduction and must do three things in order: name the failure mode, decide whether it starts in your integration or in the model's output, and pick a recovery that removes the cause. A fix that only hides the symptom (blind retries, a louder prompt, a forgiving parser) is usually the distractor.
Key rules
- Read the envelope first. A 4xx or 5xx means the request failed to process. A successful response carries
stop_reason, which says why generation stopped. - Truncation is not drift.
max_tokensormodel_context_window_exceededmeans incomplete output. A cut-off tool call or structured output needs more room (thinking also counts towardmax_tokens) or less spent on thinking. - Refusal is an HTTP 200 with
stop_reason: "refusal". Monitor it separately, discard partial output, and retry on a fallback model. Exception:reasoning_extractionmeans your prompt or schema asks for internal reasoning, so change it. - Empty
end_turnafter tool results often comes from your harness adding text aftertool_result. Fix the structure; use a new "Please continue" user message only as a last resort. pause_turnis a server-tool loop limit: append the assistant content unchanged and resend with the same tools.- Request-shape errors are yours. Every
tool_useneeds atool_result, placed first in the next user message. Thinking blocks must be replayed unmodified; on some models an editedsystem,toolsor earlier turn also invalidates their signatures. - Hallucination: allow "I don't know", extract quotes first, require a quote per claim and retract unsupported ones, restrict to the provided documents. These reduce but do not eliminate it.
- Inconsistent or drifting format: use structured outputs for guaranteed schema conformance (refusals and truncation are the exceptions). Otherwise specify the format, give examples, ground with retrieval, or chain smaller prompts. Prefill is not supported on Claude 4.6 and later models.
- Under-acting: if the request says "suggest", Claude may only suggest. Ask for the change explicitly or set a default-to-action system prompt.
- Tool misuse: wrong tool points to ambiguous descriptions (say when to use each); invented parameters point to missing
strict: true. - Context loss: inspect the payload actually sent. Your trimming or summarizing may have removed the fact. Long contexts also degrade recall (context rot), so curate, compact or clear.
- Claude Code ignores configuration: check what loaded with
/context,/hooks,/mcpand/status; isolate withclaude --safe-mode.
A minimal triage branch:
if response.stop_reason == "refusal":
handle_refusal(response.stop_details)
elif response.stop_reason in ("max_tokens", "model_context_window_exceeded"):
handle_truncation(response)
elif response.stop_reason == "pause_turn":
resend_with_assistant_turn(response)
Traps
- Retrying an identical request when the failure is deterministic: a bad history, an invalid thinking signature, or usually a refusal on the same model.
- Strengthening the prompt for a problem the model never saw, such as a trimmed constraint or an unloaded
CLAUDE.md. - Repairing truncated JSON in the parser and keeping partial data.
- Putting your own instructions inside
tool_result. Claude may treat them as untrusted and ask for confirmation. Send them in a user turn after the result, or a mid-conversation system message where supported (with a server tool still waiting, send only the results). - Counting only HTTP errors, which never shows refusals.
- Assuming a bigger context window fixes forgotten facts that were never sent.
Decide quickly
| Situation | Choice | Why |
|---|---|---|
JSON ends mid-object, max_tokens | Retry with a higher limit | Output is incomplete |
200, empty content, refusal | Fallback model | Same model usually refuses again |
reasoning_extraction | Change the prompt or schema | The request itself is the trigger |
| Claims absent from the source | Quote-first grounding and verification | Ties claims to text |
| Exact schema required | Structured outputs | Enforced, not requested |
400 about missing tool_result | Fix history construction | Integration defect |
| Suggests instead of editing | Explicit action instruction | Wording drives behavior |
| Early constraint ignored | Inspect the sent messages | Locates the loss |
| Rule ignored in Claude Code | /context before rewording | Loading versus adherence |