Topic 1 of 6 · 4 min read
Reading traces end to end
Goal: Find the first step in an agent or RAG trace where the run went wrong and explain why later errors follow from it.
A trace is the full record of one run, and you read it from the top to find the first step that went wrong, not the last output that looks wrong. Everything after that first bad step is usually a consequence, not a separate bug.
Check yourself · 1 of 3
A RAG bot gives a wrong answer. The trace shows the retriever returned an unrelated document and the model summarised it correctly. Where is the first bad step?
Why it matters
The final answer of an LLM app is the end of a chain: the user message, the system prompt, a query rewrite, a retrieval call, one or more tool calls, intermediate model outputs, then the answer. If you only read the answer, you will blame the last model call. Often the real cause is three steps earlier: the retriever returned the wrong document, or a tool returned an error that the model quietly worked around.
Each step in a trace is a span with a parent, as in OpenTelemetry. Tools such as Langfuse, LangSmith, Braintrust, Arize Phoenix or plain JSON logs all show the same shape.
How to read one
- Read the user input as the user meant it, including what they did not say.
- Walk forward step by step. At each step ask: given only what this step could see, was this output reasonable?
- Check what retrieval and tools actually returned, not what the model said they returned. Open the raw payload.
- Mark the first bad step. Note it in one line. Later errors that follow from it are not new findings.
- Check the final answer last, against what the user needed.
Before and after
A support bot told a customer "your plan includes SSO". The weak read: "the model hallucinated". Here is the trace:
{
"input": "Does the Starter plan include SSO?",
"steps": [
{"type": "retrieve", "query": "Starter plan SSO", "top_doc": "pricing-enterprise.md"},
{"type": "llm", "output": "Yes, SSO is included."}
]
}
The retriever returned the Enterprise page. The model answered faithfully from the document it was given. The first bad step is retrieval, so a prompt change would not help.
What goes wrong
- Blaming the last step. You rewrite the answer prompt while the retriever keeps feeding it the wrong page.
- Trusting the model's description of a tool result. The tool returned an empty list, the model said "no matches found, but generally...". Read the raw output.
- Reading only failures flagged by users. Silent failures, like a correct-looking answer built on a stale document, never get flagged.
- Skimming long traces. The bad step is often one line in a large context. Search for the tool name or the document id.
Reading ten traces slowly teaches more than a dashboard of averages. Do it before building any metric.
Examples
Right answer, wrong source
A RAG bot answers "Refunds take 5 days" and the answer is correct today. In the trace, the retrieved chunk is an archived 2022 policy that happens to say the same. The run passed by luck. Note it: retrieval returned an outdated document.
The silent tool error
{"tool": "get_order", "args": {"id": "A-1042"}, "result": {"error": "timeout"}}
The next model message says "Your order shipped yesterday". The tool failed and the model invented a status. First bad step: the model continued after a tool error instead of reporting it.
Key points
- A trace is the whole run: input, retrieval, tool calls, intermediate outputs and the final answer.
- Walk forward and find the first step that went wrong; later errors usually follow from it.
- Open the raw tool and retrieval payloads instead of trusting the model's description of them.
- Blaming the final model call hides retrieval, tool and routing bugs that sit earlier.
- Reading a few traces slowly beats reading a dashboard of averages.
Common mistakes
- Reading only the final answer and guessing the cause.
- Fixing the last step when the first bad step is retrieval or a tool call.
- Counting every downstream error as its own bug.
- Skipping traces that look fine, so wrong-but-plausible answers are never examined.
Check yourself · 2 of 3
A tool call in a trace returned {"error": "timeout"}, and the next model message states an order status as fact. What do you record?
Check yourself · 3 of 3
You open a trace with eight steps. What is the most useful way to read it?
Practice items, not counted towards your mastery.
Start here
- LLM Evals: Everything You Need to Know (Hamel Husain and Shreya Shankar) (opens in a new tab)ArticleFree
Practical answers on reading traces, open coding, sample sizes and when to build an evaluator.
- A Field Guide to Rapidly Improving AI Products (Hamel Husain) (opens in a new tab)ArticleFree
Argues that looking at data and counting failure modes beats generic metrics, with worked examples.
- An LLM-as-Judge Won't Save The Product, Fixing Your Process Will (Eugene Yan) (opens in a new tab)ArticleFree
Shows why labeling real outputs and iterating on the process matters more than any judge prompt.
More for this topic
- Traces (OpenTelemetry) (opens in a new tab)DocsFree
Defines spans and parent-child structure, the model behind most LLM trace viewers.