Topic 1 of 5 · 4 min read
Mining production traces for failure cases
Goal: From a set of production traces, choose the ones that should become eval cases and name each failure category.
Do not read production traces at random: sample them by signal, read them yourself, and group the failures into named categories before you write a single eval. The categories are the output. A pile of bad examples is not.
Check yourself · 1 of 3
Why include a small random sample of unflagged traces when mining production logs?
Why it matters
A busy feature produces thousands of traces a day. Nobody can read them all, and the average score hides the failures that matter. Your pre-launch eval set was written from your own guesses. Production shows what users really ask, and it will contain failures you never imagined.
How to do it
- Pick the signals. Each trace should carry a trace id and a few cheap flags: a low automated score, a thumbs down, a user retry within a minute, a hand-off to a human, a tool error, an unusually long answer, a refusal.
- Sample, do not skim. Take a fixed number from each signal bucket, plus a small random slice of traces with no flags. The random slice tells you how many failures your signals miss.
- Read the whole trace. Open the user message, the retrieved context, the tool calls and the answer. Write one line of free text about what went wrong. Do not use a pre-made list yet.
- Group the notes into categories. After 50 to 100 traces, similar notes cluster. Name each cluster by what the system did wrong, such as "cites a policy that was not retrieved" or "calls refund tool without an order id".
- Count and rank. Categories with a count and a business cost tell you what to fix and which cases to add first.
Before and after
Weak: a ticket that says "answers are sometimes wrong, collect 200 bad chats". Better:
# triage.py: one row per sampled trace
rows = [
{"trace_id": "tr_8f21", "signal": "thumbs_down",
"note": "answered from memory, no doc retrieved", "category": "ungrounded-answer"},
{"trace_id": "tr_90ac", "signal": "retry",
"note": "asked for order status, bot asked for order id twice", "category": "ignores-given-info"},
{"trace_id": "tr_77d0", "signal": "random",
"note": "fine", "category": None},
]
What goes wrong
- Sampling only thumbs down. Few users vote, so you read a biased slice. Add the random slice.
- Categories made up before reading. A fixed list such as "hallucination, tone, other" hides the real causes. Let them emerge from the notes.
- Trusting an automated score blindly. A judge model can be wrong. Check a sample of its low and high scores yourself.
- Losing the link. If the row has no trace id, nobody can find the full conversation again.
Examples
Three buckets, one afternoon
A support bot logs 4,000 traces a day. An engineer pulls 20 thumbs-down traces, 20 where the user retried within a minute, 20 handed off to a human and 20 random ones. After reading 80 traces she has five categories. The largest, "asks for the order id the user already gave", appears in 17 of them and in 2 of the 20 random traces, so it is not only a thumbs-down artefact.
A category with a name you can test
"Bad answers" cannot become an eval. "States a refund window that is not in the retrieved policy" can: the grader checks the stated number against the retrieved text. A category is useful when you can write a pass or fail check for it.
Key points
- Sample production traces by signal, such as low score, thumbs down, retry or escalation, instead of reading at random.
- Always include a small random slice of unflagged traces to measure what your signals miss.
- Read the whole trace and write a free-text note before choosing any category.
- Name each failure category by what the system did wrong, then count and rank the categories.
- Keep the trace id on every row so the full conversation can be reopened later.
Common mistakes
- Sampling only the traces users rated, which are a small and unrepresentative group.
- Choosing categories from a generic list before reading any trace.
- Skipping the random slice, so you never learn how many failures carry no signal.
- Keeping notes without trace ids, so cases cannot be rebuilt later.
Check yourself · 2 of 3
What should come first when turning a batch of bad traces into failure categories?
Check yourself · 3 of 3
A trace row says "bad answer, thumbs down" and has no trace id. What is the main problem?
Practice items, not counted towards your mastery.
Start here
- Your AI product needs evals (Hamel Husain) (opens in a new tab)ArticleFree
Explains why looking at real traces and building evals from them is the core loop of improving an LLM product.
- A Field Guide to Rapidly Improving AI Products (Hamel Husain) (opens in a new tab)ArticleFree
Practical advice on error analysis, reading data and building a feedback loop around real failures.
- Patterns for Building LLM-based Systems and Products (Eugene Yan) (opens in a new tab)ArticleFree
Covers evals and collecting user feedback as the base of a data flywheel for LLM products.