---
title: "Read the trace before you touch the prompt"
url: https://eldan.ai/writing/read-the-trace-first
canonical: https://eldan.ai/writing/read-the-trace-first
locale: en
language: en
published: 2026-10-09
updated: 2026-11-23
author: "Eldan Abdrashim"
cite_as: "Eldan Abdrashim. \"Read the trace before you touch the prompt.\" Eldan.ai, 9 October 2026, updated 23 November 2026. https://eldan.ai/writing/read-the-trace-first."
---

# Read the trace before you touch the prompt

> When an agent misbehaves, the reflex is to edit the prompt. Read the trace first: which tools ran with which arguments, what they returned, what the model actually saw and where the time went. A six-step checklist.

An agent gives a customer the wrong delivery date. Someone opens the system prompt and adds a sentence: “Always check the order status before answering questions about delivery.” The next week a different answer is wrong, and another sentence goes in. After a month the prompt is two pages long, nobody can say which sentence fixed what, and the agent is not noticeably better.

The prompt is the most visible part of an agent, so it is where people reach first. It is also the part least likely to be the cause. In the example above, the order lookup may have returned an empty list because the agent passed the date in the wrong format. Or the result came back fine and was cut out of the context two steps later. No sentence in the system prompt fixes either of those, and each new sentence makes the real cause harder to find.

My rule is simple: read the trace before you touch the prompt.

## What a trace shows

A trace is the record of one run, as a tree of spans. Each model call, tool call and retrieval is a span with its input, output, timing, token counts and errors. Reading one is like reading the call stack of a crashed program: you stop guessing and start following what actually happened.

The OpenTelemetry project has [semantic conventions for generative AI](https://github.com/open-telemetry/semantic-conventions-genai) that name these pieces, so traces from different tools look alike. They are still marked as in development, but the names are useful even if you never install a tracing backend. A model call has an operation name such as `chat`. A tool execution span is named `execute_tool` plus the tool name, and carries `gen_ai.tool.name`, plus the arguments and result when you choose to record them.[^1] Token usage goes in `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`.

You do not need a platform to start. If your spans end up as JSON lines in a file, a short script prints a run in a form you can read:

```python
import json

def print_run(path: str, preview: int = 120) -> None:
    spans = [json.loads(line) for line in open(path)]
    by_id = {s["span_id"]: s for s in spans}

    def depth(s):
        d = 0
        while s.get("parent_id") in by_id:
            s, d = by_id[s["parent_id"]], d + 1
        return d

    for s in sorted(spans, key=lambda s: s["start_ms"]):
        a = s.get("attributes", {})
        ms = s["end_ms"] - s["start_ms"]
        tokens = a.get("gen_ai.usage.input_tokens", "")
        error = a.get("error.type", "")
        print(f"{'  ' * depth(s)}{s['name']}  {ms} ms  {tokens}  {error}")
        for key in ("gen_ai.tool.call.arguments", "gen_ai.tool.call.result"):
            if key in a:
                print(f"{'  ' * depth(s)}  {key.rsplit('.', 1)[-1]}: {str(a[key])[:preview]}")
```

## The checklist

These are the six steps I go through for every failed run, in this order.

1. **Find the first wrong step, not the last.** The wrong answer the user saw is usually several steps after the first mistake. Walk the run from the top and stop at the first span whose output you would not accept.
2. **Check which tool was called.** Was it the right tool? If the agent searched the documentation when it should have looked up the order, the problem is usually in the tool names and descriptions: two tools that sound alike, or a needed tool that does not exist. Fix the tool definitions, not the system prompt.
3. **Read the arguments exactly as sent.** Dates, IDs, units, quoting, pagination. Many failures that look like reasoning errors are arguments that seem reasonable and do not match what the API expects: a customer name where an ID was needed, a local date where UTC was needed.
4. **Read what came back, and what the model saw.** Compare the raw tool result with the message that went into the context. Look for empty results, errors swallowed and reported as “no results”, outputs truncated to fit, and large blobs that push the important part out of view. A model cannot use what it never saw.
5. **See where the time and tokens went.** Sort spans by duration. Look for identical calls repeated in a loop, retries hidden inside a client library, slow tools that run one after another when they could run in parallel, and input tokens that grow every step because full results are appended each time.
6. **Name the cause, then change one thing.** Classify the failure: a tool bug, a tool-interface bug, a context bug, or a model judgement error. Only the last one is a prompt problem. Make one change, then rerun the same input and read the new trace.

Step six has a second half: save the failing run as a test. Record the user input and the tool responses, and replay them against the agent after every change. A trace you debugged once and threw away is a regression you will debug again.

## Make traces worth reading

A trace is only as good as what you record. A few habits pay for themselves quickly.

Put the prompt version, the model name and the tool definitions version on the root span. When behaviour changes, the first question is what changed, and the trace should answer it without a search through deploy logs.

Record retries as separate spans. A call that succeeded on the third attempt looks fast and healthy if only the last attempt is logged.

Keep full arguments and results in development and staging. In production, decide deliberately what you keep, where it is stored and for how long, because tool results often contain customer data.

Count, do not only read. After you have triaged twenty failures, tally the causes.[^2] If most are context bugs, your effort belongs in how results are trimmed and summarised, and no amount of prompt work will move the number.

## Where this leads

Reading traces turns agent debugging from a guessing game into ordinary work: find the first wrong step, explain it, change one thing, keep the case as a test. The prompt still matters. It is just rarely the first suspect.

The glossary entries on [observability](/glossary/observability) and the [agent loop](/glossary/agent-loop) define the terms used here. The section “Observe and test” in [Agents and MCP in Production](/workshops/agents-and-mcp) covers tracing an agent run and building replay tests from recorded runs.

[^1]: The conventions treat prompts, outputs, tool arguments and tool results as sensitive and recommend that instrumentation not capture them by default. Turn capture on deliberately, and decide where those traces may live.
[^2]: Write down the step number of the first mistake for each failure too. If most first mistakes happen at step one or two, the problem is how the agent reads the request, not what happens later.

_Agents · Observability_
