Building a Failure Taxonomy from 20 Runs
Build a failure taxonomy from twenty recorded agent runs (a fixture): grade each run, label each failed run by the first step that went wrong (tool selection, arguments, missing context, reasoning or environment), treat an exhausted budget as a symptom, and rank fixes by frequency with a confidence interval.
Contentsand lesson path
On this page
- From Ad-Hoc Bug Fixing to Systematic Failure Taxonomies
- Methodology: Automated Classification and Aggregation
- Lab: Label Twenty Runs, Then Automate
- Practice questions
- Apply it
- Review prompt
Lessons of Agent Tracing & Debugging
- Why Agents Need Traces, Not Just Logs Concept · 15 min
- Lab: Instrumenting the Loop with Spans Lab · 25 min
- Reading a Failed Trace Worked example · 20 min
- Building a Failure Taxonomy from 20 Runs Lab · 25 min
- Cost and Latency per Step Worked example · 15 min
- Check: Find the Faulty Step Knowledge check · 6 questions
What you will learn
- Diagnose a failed run from its trace and classify the failure (tool selection, arguments, missing context, reasoning or environment).
01. From Ad-Hoc Bug Fixing to Systematic Failure Taxonomies
When a team first puts an agent in front of users, debugging is usually one bug report at a time. An engineer sees a failed customer ticket, opens the logs, finds that the agent passed a wrong argument to a tool, edits the system prompt and deploys the change. Two days later a similar request, worded a little differently, fails again, and the next quick prompt edit breaks something that used to work.
This reactive prompt-churn cycle is risky because agent outputs are probabilistic: the same input can succeed on one run and fail on the next. A single bug report says almost nothing about how often a failure happens or how failures are distributed. Suppose one edge case occurs in 0.5% of sessions and another failure mode in 30%: without counts, a team can spend days on the first while the second goes unaddressed.
A prompt change made for one incident can also cause regressions elsewhere. For example, an edit meant to stop the agent from querying a slow database tool might make it invent answers instead, turning a latency problem into a correctness problem.
To make reliability work measurable, move from ad-hoc debugging to systematic failure taxonomy analysis. A failure taxonomy is a classification built from observed runs: it groups agent failures into a small set of categories, and each failed run gets one primary category.
A useful starting set of categories, matching where in the run things first went wrong:
- Tool selection: the model called the wrong tool, or no tool when one was needed.
- Arguments: the right tool with bad arguments: a wrong type, a missing required field, or an invented parameter name.
- Missing context: the information needed was not in the prompt, or an old value from an earlier turn was used.
- Reasoning: the model had what it needed but drew a wrong conclusion, lost the goal or repeated itself.
- Environment: the tool or infrastructure failed: a 503, a timeout, a permission error.
An exhausted turn or token budget is a symptom, not a cause: record it as a flag and label the run by what made it loop. Expect to add or split categories after you read your own traces.
02. Methodology: Automated Classification and Aggregation
Build the taxonomy in this order:
-
Grade outcomes first. Run the eval set and check every final answer against what was expected. A run is a failure when the answer is wrong, whether or not any span errored. Wrong answers from error-free runs are often the largest group, and a classifier that only looks at error spans never sees them.
-
Read and label by hand. For every failed run (and a sample of passing ones), read the trace and write one line: the first thing that went wrong. Then group the notes into categories. With 20 runs this takes under an hour, and it is how you discover categories you did not expect.
-
Automate only what has a reliable signal. Map specific
error.typevalues and HTTP status codes to categories with an explicit table, and send everything else tounclassifiedinstead of a default bucket. Compare the automatic labels with your manual ones before you trust them. -
Count with care. With 20 runs, 3 failures against 2 is not a meaningful difference. Report counts with an interval and collect more runs before you rank close categories.
The script below does steps 1, 3 and 4 on exported traces; the lab supplies the traces and the manual labels for step 2.
"""Grade outcomes first, compare rule-based labels with manual ones, then count."""
import json
import math
from collections import Counter
from labels import MANUAL
RULES = { # explicit mapping; anything else is "unclassified", never a guess
"TimeoutError": "environment", "ConnectionError": "environment",
"PermissionError": "environment", "ValidationError": "arguments",
}
def auto_label(trace):
for span in trace["spans"]:
err, code = span["error.type"], span["http.response.status_code"]
if err == "HTTPError" and code and (code >= 500 or code in (401, 403, 429)):
return "environment"
if err in RULES:
return RULES[err]
return "unclassified" # wrong answers without an error span land here
def wilson(k, n, z=1.96):
p, d = k / n, 1 + z * z / n
mid = (p + z * z / (2 * n)) / d
half = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / d
return max(0.0, mid - half), min(1.0, mid + half)
traces = json.load(open("benchmark_20.json"))
failed = [t for t in traces if t["final_answer"] != t["expected"]]
silent = [t["run_id"] for t in failed
if all(s["status"] != "ERROR" for s in t["spans"])]
print(f"graded: {len(traces) - len(failed)} passed, {len(failed)} failed; "
f"{len(silent)} failed with no error span: {silent}")
print(f"{'run':<4} {'manual':<16} {'rules':<13} first thing that went wrong")
agree = 0
for t in failed:
manual, note = MANUAL[t["run_id"]]
auto = auto_label(t)
agree += manual == auto
print(f"{t['run_id']:<4} {manual:<16} {auto:<13} {note}")
print(f"rules agree with manual labels on {agree}/{len(failed)} failed runs")
print("category counts (manual), with 95% Wilson interval out of 20 runs:")
for category, k in Counter(label for label, _ in MANUAL.values()).most_common():
low, high = wilson(k, len(traces))
print(f" {category:<16} {k} [{low:.0%} - {high:.0%}]")03. Lab: Label Twenty Runs, Then Automate
You will grade 20 exported traces from a customer-service agent, label the failures by reading them, and see how far a rule-based classifier gets. The traces are a fixture written by a script, in a simplified export format: each has the expected answer, the agent's final answer and its tool spans with status, error.type, HTTP status and a detail field standing in for the span inputs and outputs you would read in a trace viewer.
You need: Python 3.12 or later; standard library only. Tested with Python 3.12.13. Create a folder taxonomy-lab, save taxonomy.py from above and the three files below into it.
Step 1: create the traces. Save make_runs.py below and run it. It writes the 20 traces to benchmark_20.json in the current folder.
"""Writes benchmark_20.json: 20 exported agent traces in a simplified format."""
import json
# id, expected, answer, [(span, error.type, http status, what the span shows)]
RUNS = [
("r01", "refund 40", "refund 40", [("execute_tool get_order", None, None, "")]),
("r02", "zip 10115", "zip 10115", [("execute_tool lookup_zip", None, None, "")]),
("r03", "refund 25", "refund 25", [("execute_tool get_order", None, None, "")]),
("r04", "eta 3 days", None, [("execute_tool supplier_eta", "HTTPError", 503,
"supplier API down")]),
("r05", "plan pro", "plan pro", [("execute_tool get_account", None, None, "")]),
("r06", "order 77", None, [("execute_tool search_orders", None, None,
"same query 4 times"),
("invoke_agent", "BudgetExceeded", None, "")]),
("r07", "refund 15", "refund 0", [("execute_tool get_invoice", None, None,
"read invoice, not the order")]),
("r08", "tier gold", None, [("execute_tool get_account", "ValidationError", None,
"invented field tier_level")]),
("r09", "eta 2 days", "eta 2 days",
[("execute_tool supplier_eta", None, None, "")]),
("r10", "balance 90", None, [("execute_tool query_db", "TimeoutError", None,
"db timed out after 5 s")]),
("r11", "refund 60", "refund 60", [("execute_tool get_order", None, None, "")]),
("r12", "cancel ok", "cancel ok", [("execute_tool cancel_order", None, None, "")]),
("r13", "email sent", None, [("execute_tool send_email", "ValidationError", None,
"missing required email")]),
("r14", "refund 10", "refund 10", [("execute_tool get_order", None, None, "")]),
("r15", "address NL", "address DE", [("execute_tool get_account", None, None,
"used old address from a prior turn")]),
("r16", "plan basic", "plan basic", [("execute_tool get_account", None, None, "")]),
("r17", "refund 35", "refund 35", [("execute_tool get_order", None, None, "")]),
("r18", "notes ok", None, [("execute_tool read_notes", "PermissionError", 403,
"token lacks notes:read")]),
("r19", "refund 20", "refund 0", [("execute_tool get_order", None, None,
"said policy forbids it; it does not")]),
("r20", "zip 75001", "zip 75001", [("execute_tool lookup_zip", None, None, "")]),
]
traces = []
for run_id, expected, answer, spans in RUNS:
traces.append({"run_id": run_id, "expected": expected, "final_answer": answer,
"spans": [{"name": name, "status": "ERROR" if err else "UNSET",
"error.type": err, "http.response.status_code": code,
"detail": note} for name, err, code, note in spans]})
with open("benchmark_20.json", "w") as f:
json.dump(traces, f, indent=1)
print(f"wrote {len(traces)} traces")python3 make_runs.pywrote 20 tracesStep 2: read failed traces. Print one trace and decide what went wrong first. Run r07 has no error span at all, but its answer is wrong: the agent read the invoice instead of the order. That is a tool-selection failure that no exception-based rule can see.
"""Prints one trace so you can read it: python3 show_trace.py r07"""
import json
import sys
for trace in json.load(open("benchmark_20.json")):
if trace["run_id"] == sys.argv[1]:
print(json.dumps(trace, indent=1))python3 show_trace.py r07{
"run_id": "r07",
"expected": "refund 15",
"final_answer": "refund 0",
"spans": [
{
"name": "execute_tool get_invoice",
"status": "UNSET",
"error.type": null,
"http.response.status_code": null,
"detail": "read invoice, not the order"
}
]
}Step 3: write the manual labels. Read each failed run the same way and record a category and a one-line note. These are ours; change any you disagree with and rerun step 4.
"""Manual labels: written after reading each failed trace, before any automation.
Format: run_id -> (category, the first thing that went wrong)."""
MANUAL = {
"r04": ("environment", "supplier API returned 503"),
"r06": ("reasoning", "repeated one search 4 times; hit the budget"),
"r07": ("tool selection", "read the invoice instead of the order"),
"r08": ("arguments", "invented field tier_level"),
"r10": ("environment", "database timed out"),
"r13": ("arguments", "left out the required email"),
"r15": ("missing context", "used an old address from an earlier turn"),
"r18": ("environment", "token lacks the notes:read scope"),
"r19": ("reasoning", "claimed a refund rule that does not exist"),
}Step 4: grade, compare and count. Run taxonomy.py. It grades every run against its expected answer, prints the manual and the rule-based label of each failed run side by side, and counts the manual categories with a 95% Wilson interval.
python3 taxonomy.pygraded: 11 passed, 9 failed; 3 failed with no error span: ['r07', 'r15', 'r19']
run manual rules first thing that went wrong
r04 environment environment supplier API returned 503
r06 reasoning unclassified repeated one search 4 times; hit the budget
r07 tool selection unclassified read the invoice instead of the order
r08 arguments arguments invented field tier_level
r10 environment environment database timed out
r13 arguments arguments left out the required email
r15 missing context unclassified used an old address from an earlier turn
r18 environment environment token lacks the notes:read scope
r19 reasoning unclassified claimed a refund rule that does not exist
rules agree with manual labels on 5/9 failed runs
category counts (manual), with 95% Wilson interval out of 20 runs:
environment 3 [5% - 36%]
reasoning 2 [3% - 30%]
arguments 2 [3% - 30%]
tool selection 1 [1% - 24%]
missing context 1 [1% - 24%]- Nine of 20 runs failed, and three of them never raised an error. A success rate taken from span status would have reported 14 passes, because only six runs (r04, r06, r08, r10, r13, r18) have an error span.
- The rules agree with the manual labels on 5 of 9 failures: the environment and argument failures, which leave an exception. Tool selection, missing context and reasoning stay
unclassified, which is honest; a default bucket would have hidden them. - Environment leads with 3 failures, but its interval (5% to 36%) overlaps every other category. These 20 runs cannot tell you which category to fix first; run more tasks, or the same tasks several times, before ranking them.
04. Practice questions
05. Apply it
To use a failure taxonomy in your own evaluation pipeline:
- Keep a benchmark suite of at least 20 to 50 varied tasks that reflect real production use.
- Read failed traces and write one-line notes before you automate anything; automate only the categories with a reliable signal, and send the rest to an unclassified bucket.
- Run the taxonomy benchmark on every pull request, to check that a fix reduces its target category without raising others.
- Fix the most frequent category first, once the counts are large enough to tell categories apart; report intervals, not just counts.
- Read the unclassified and rare failures from time to time, to spot new patterns as models change.
06. Review prompt
Explain what a failure taxonomy built from your own traces tells you that a single pass rate does not. Name the five categories used in this lesson (tool selection, arguments, missing context, reasoning, environment), explain why outcomes must be graded before failures are classified, and say what 20 runs can and cannot tell you about priorities.
References
- OpenTelemetry GenAI semantic conventions: spans (Development status)
- OpenTelemetry GenAI semantic conventions: inference spans
- OpenTelemetry GenAI semantic conventions: agent spans
- Langfuse documentation
- Hamel Husain: LLM evals FAQ (error analysis)
- NIST/SEMATECH e-Handbook: Confidence intervals for a proportion
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.