Debugging LLM System Failures
Failure taxonomy (design guidance)
| Symptom | Likely layer |
|---|---|
| Wrong or missing facts | Context or retrieval (the information never reached the model) |
| Ignores a rule | Prompt (conflict, burial, too long) or a rule that needed enforcement |
| Calls the wrong tool or wrong arguments | Tool interface (descriptions overlap, schema unclear, too many tools) |
| Truncated or malformed output | Limits (max_tokens, schema, streaming parsed early) |
| Good in testing, bad in production | Data drift, different inputs, prompt or model version mismatch |
| Intermittent failures | Non-determinism, transient tool or API errors, race conditions |
| Cost or latency spike | Caching broke, context bloat, retries, agent loop growth |
| Confident but wrong | Hallucination (grounding, retrieval, validation gaps) |
| Refuses unexpectedly | Safety refusal, prompt wording, reasoning_extraction pattern |
Method (design guidance)
- Reproduce with the exact inputs, prompt version, tool results and model; capture the full request and response.
- Read the evidence:
stop_reason,usage(including cache fields), tool calls and results, and the final text. Checkstop_reasonfirst (truncation, refusal, context overflow) (1.1). - Isolate the layer by changing one thing at a time: give the correct context directly (does it now work?), simplify the prompt, replace a tool with a stub, swap the model tier, lower temperature or effort.
- Form a hypothesis, then test it against several cases, not one.
- Fix at the right layer (enforce in code if a prompt rule must hold; fix the tool description if selection is wrong; fix retrieval if facts are missing).
- Add a regression case and re-run the suite (D4.1).
Useful tooling
- Claude Code:
claude --debugshows parse errors (for example invalid rule frontmatter);/doctor prompt-auditaudits instruction files (CLAUDE.md, rules, skills, commands, subagents) for problems;/mcpshows server status. - Hooks can log every tool call and result for later inspection (1.5).
- Telemetry (OpenTelemetry traces and events) reveals which tool, which step and how long (D3.4).
- Hook not firing? Check event name case, matcher against the tool name (not path), and whether
max_turnsended the session first (1.5). - Empty
end_turnafter tool results? Text added aftertool_resultblocks can teach the model to end its turn.
Common root causes worth checking first
- Missing or stale context (retrieval miss, truncated history).
- Overlapping tool descriptions.
- Contradictory instructions across prompt layers or files.
max_tokenstoo low.- Cache invalidation from changing tools or
tool_choicemid-session. - A model upgrade with an unchanged prompt.
Exam traps
- Rewriting the whole prompt instead of isolating the layer.
- Debugging from one example.
- Blaming the model when the context lacked the answer.
- Fixing a hard requirement with a stronger prompt.
- No regression test after the fix.
References
- Handling stop reasons — checked Oct 16, 2026
- Prompt caching — checked Oct 16, 2026
- Hooks in the SDK — checked Oct 16, 2026
- How Claude remembers your project — checked Oct 16, 2026
Check your understanding
First thing to check when output ends mid-sentence?Show answerHide answer
Answer
stop_reason; likelymax_tokensor context limit.The model "ignores" a policy it was told. Fix?Show answerHide answer
Answer
Check for conflicts or burial; if it must always hold, enforce in code or a hook.How do you prove a fix works?Show answerHide answer
Answer
A regression case in the evaluation suite that failed before and passes after.