By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Two tickets arrive a minute apart, both asking where order A17 is. Both get a 200 OK and a fluent three-sentence answer. One is right. The other says the parcel shipped yesterday, while the warehouse still has it on hold.
Your dashboard is green. Latency is normal, the schema validated, and the evaluation scored the answer as fluent. Nothing there can tell you which layer produced the wrong sentence. That is the problem: model output is the last place a failure shows up.
You open the tool span, then the exact string the model received. That string is the evidence. The last model call is a consequence, not a cause, and its fluent tone proves only that the model writes well.
A trace is the ordered record of one request. A span is one timed operation inside it: the outbound HTTP call, the tool execution, the second model call. If your logs print one line per request, you have a log, not a trace. Without span order you cannot tell which layer moved first.
| Span | A healthy span shows | A broken span shows |
|---|---|---|
| request | The assembled payload, token count, tool list | A truncated history, a missing tool, a stale context block |
| model call 1 | stop_reason, latency, token usage | An error status, an empty content block, a refusal |
| tool | Tool name, arguments, duration, result size | A timeout, a failed validation, a result of zero characters |
| model call 2 | stop_reason of end_turn, schema pass | An answer built from an error string |
Keep one field most teams omit: the payload as sent, truncated to a few hundred characters. A span that records only a duration tells you where the time went, not where the truth changed.
Start at the first span whose status is an error. Then read every span after it and ask one question: did the next step know about the failure? The model only sees the text of your tool_result. If you send a raw exception, the model will narrate it, work around it, or invent an outcome.
# Read a trace by span order, not by log line.
# The input is a recorded trace; no model is called.
TRACE = [
{"span": "request", "status": "ok", "duration_ms": 2},
{"span": "model:1", "status": "ok", "stop_reason": "tool_use", "duration_ms": 640},
{"span": "tool:lookup_order", "status": "error", "error": "upstream_timeout", "duration_ms": 5000},
{"span": "model:2", "status": "ok", "stop_reason": "end_turn", "duration_ms": 720},
]
def first_error(trace):
for index, span in enumerate(trace):
if span["status"] == "error":
return index
return -1
def spans_after(trace, index):
return [span["span"] for span in trace[index + 1:]]
index = first_error(TRACE)
print("first error:", TRACE[index]["span"])
print("spans after it:", spans_after(TRACE, index))The function returns an index, not a sentence, because the next question is about order. model:2 ran after the error, so whatever it wrote was written with an error string in context. That one fact separates a model-output bug from a missing error contract.
The same four spans cover every failure in this lesson. Switch the scenario chips below and watch which span carries the fault. The shape never changes; the class does.
A trace tells you what happened. A diff tells you what changed. Run these three comparisons in order and most layers fall out.
tool_result you sent with what the tool actually returned. Truncation and silent wrapping live here.The second diff catches the failure that survives code review. Your tool returns a nested object, your serializer flattens it, and the model receives a field nobody tested. The logs agree; only the diff disagrees.
A trace proves what happened inside your request. It cannot tell you whether the source was right or whether the answer was good. Those need a fixture and a property, which is the next lesson.
Take the four-span trace from this lesson and answer three questions on paper.
Then add one field to your own trace so the second question is answerable without another tool: the tool_result text, stored verbatim.
Key takeaways
A trace is ordered spans. One log line per request cannot isolate a layer.
Open the first error span, never the last. The final answer is a consequence.
The model sees only the tool_result string you send, not the tool's real return value.
Three diffs isolate most layers: the request, the returned string, the prompt.
Green spans with a wrong answer mean context or data, not transport.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.