Overview
Curated: · Written: · Reviewed:
Troubleshooting LLM, RAG & Agent Systems
In one line
When an LLM, RAG or agent system fails in production, walk the symptom down the stack of contracts (prompt, retrieval, ranking, context assembly, decoding, agent loop, tool execution) to the first contract that broke, prove it with the cheapest separating experiment, and change only that layer. Reach for this method whenever the failure is a symptom like "the AI hallucinated" and you have not yet classified it.
Key definitions
- Broken contract: the first layer whose output fails what the next layer needs; the bug lives there, and everything above it is downstream noise.
- recall@k: the fraction of queries whose gold chunk appears in the top k candidates.
- MRR: mean of 1/rank of the first relevant result across queries.
- Faithfulness: whether the generated claims are supported by the retrieved context.
- Idempotency key: a client-supplied key that lets the server return the stored result for a repeated request instead of acting twice.
- Livelock: agents keep exchanging messages and spending tokens with no change in shared state or progress toward the terminal criterion.
- Mutable alias: a model or index name (e.g.
gpt-4o-mini) that can resolve to a different version without a deploy you made.
Formulas and complexity
How it works
Classify the symptom before you touch anything: name the class (retrieval, truncation, tool authorization, cache or version mixing, evaluator defect and so on). Contain first when the failure is disclosure, unsafe action or duplicate side effects. Then run one separating experiment per fork, cheapest first: replay the captured trace before you reproduce live, and reproduce live before you change production. Vary one layer at a time.
When to use and when not to
| Situation | Use the layered method? | Why |
|---|---|---|
| Failure reproduces from a captured trace | Yes | Replay separates layers cheaply |
| Live disclosure or duplicate spend | Contain first, diagnose second | Stop the harm before the experiment |
| One unreproducible sample, low impact | No | Gather more samples and look for a cohort pattern |
| Template has a plain unresolved placeholder | No, fix and add a test | The experiment costs more than the fix |
| Suspect the judge, not the system | Verify the evaluator first | A bad judge makes a good system look broken |
| Latency spike with no output defect | Yes, but split infra from model | Compare span timings and provider error codes |
Traps interviewers probe
- "Temperature 0 makes it deterministic." It makes the output stable enough to bisect. Batching and floating-point reduction order still vary, so record the uncertainty instead of claiming a replay proves cause.
- "Reranking fixes recall." Reranking reorders candidates and cannot invent them. If recall@100 is bad, fix ingestion or the embedding.
- "A better model fixes retrieval." Generation cannot cite a chunk that was never retrieved. Check recall before blaming synthesis.
- "The output looks like hallucination, so tweak the prompt." A prompt edit that appears to fix a retrieval miss is a coincidence. Find the broken contract first.
- "Retry the timed-out tool call." Transport failure does not prove the side effect didn't happen. Check authoritative state and reuse the same idempotency key.
Interview tips
Open by naming the class of failure and the first contract you would check, not by proposing a prompt edit. Say which trace field settles each fork.
Follow-ups to expect:
- How do you debug a failure that only reproduces in production? Capture-then-replay with fixtures, plus cohort sampling to compare failing and passing cohorts.
- What if the evaluator is wrong? Verify dataset version, labels, judge model, prompt and parser; compare against deterministic checks.
- The model got worse overnight and nothing deployed. Check the alias and index versions first.
- How do you know the fix worked? The original reproducer passes, regressions are green against the pinned baseline, and the canary moves the metric with attribution.
30-second outline: "First I'd contain if there's disclosure or duplicate spend, and pin the versions in the trace. Then I'd name the class and walk the symptom down the stack. The experiment that separates the forks is replaying the captured trace with one layer varied. Once I find the first broken contract, I fix that layer, rerun the reproducer and the regression suite against the pinned baseline, and add the monitoring that would have caught it."
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.