Topic 5 of 5 · 4 min read
Turning agent failures into regression cases
Goal: Convert a debugged agent failure into a regression eval case with an input, the expected behaviour and a grader.
When you fix an agent failure, save it as an eval case: the input that triggered it, a description of correct behaviour, and a grader that checks it. Then it runs on every future change.
Check yourself · 1 of 3
What does a good regression eval case for a fixed agent failure contain?
Why it matters
Agents change all the time: new prompts, new tools, new model versions. A fix that works today can quietly break next month when someone edits the prompt for another reason. A regression case is how the team remembers. Production failures are also the most realistic test data you will ever get, because real users wrote them.
How to do it
- Take the failing input. Use the real user message and the starting state, such as the account, the files and the tool data. Remove personal data and secrets first.
- Describe correct behaviour, not the exact words. Models phrase things differently each time. Write what must be true: "asks which of the two matching orders to refund before calling refund". Avoid expecting a fixed sentence.
- Choose a grader. Use the cheapest one that can decide.
- A code check for things you can test: the
refundtool was not called before a question was asked, the output is valid JSON, the file changed as expected. - A model grader with a clear rubric for qualities code cannot see, such as tone or whether a summary is faithful. Check it against a few human-labelled examples first.
- A human review for rare, high-stakes cases.
- A code check for things you can test: the
- Check both directions. The case must fail on the old agent and pass on the fixed one. If it passes on both, it tests nothing.
- Grade the outcome and the key steps. If the outcome is the same but the route is unsafe, such as a refund made without confirmation, add a check on the tool calls.
- Run it enough times. Because runs vary, run each case several times and track the pass rate, not one result.
- Keep it linked. Note the trace or ticket it came from and the date, so a future failure can be traced back.
Before and after
Weak: after the fix, someone writes in the ticket "tested manually, works".
Better: the ticket links an eval case with the original input, a code grader that fails if refund is called before a clarifying question, a record that the old version failed 7 of 10 runs, and the fixed version passed 20 of 20.
What goes wrong
- Exact-string expectations. The case fails whenever the wording changes and people start ignoring it.
- A grader that never fails. Always check it on the broken version.
- Cases with no owner or source. Nobody knows if a failing case is still right.
- Only happy-path cases. The suite then passes while the failures that hurt users return.
Examples
A regression case as data
{
"id": "refund-two-matches",
"source": "trace 8c1f, 2026-11-20",
"input": "Please refund my last order. Email: j@example.com",
"fixtures": { "orders": ["4417", "4471"] },
"expect": "Asks which order before calling refund",
"grader": { "type": "code", "fail_if": "refund called before an assistant question" },
"runs": 10,
"min_pass": 10
}
The case says what must be true, where it came from and how many runs must pass.
A grader that tests nothing
A team adds a case with the check answer contains "refund". The old, broken agent also says "refund" in its answer, so the case passes on both versions. A better check looks at the tool call log: did refund run before the agent asked which order? Run it on the old agent first. It must fail there.
Key points
- Save each fixed failure as an eval case with the real input, expected behaviour and a grader.
- Describe correct behaviour as properties that must hold, not as an exact expected sentence.
- Prefer code graders where they can decide, a model grader with a rubric for qualities code cannot check, and humans for rare high-stakes cases.
- Confirm that the case fails on the old version and passes on the fixed one.
- Run each case several times and track a pass rate, because agent runs vary.
Common mistakes
- Expecting an exact sentence, so harmless wording changes fail the case.
- Never running the new case on the broken version to check that it fails.
- Saving the input but not the fixtures, so the case cannot be rerun.
- Leaving real customer data in the saved input.
Check yourself · 2 of 3
Why should an eval case describe expected behaviour rather than an exact expected sentence?
Check yourself · 3 of 3
You add a regression case for a fixed bug. What should you check before trusting it?
Practice items, not counted towards your mastery.
Start here
- OpenTelemetry semantic conventions for generative AI (opens in a new tab)StandardFree
The standard names for model-call and tool-call spans and their attributes, so traces look the same across tools.
- Langfuse observability overview (opens in a new tab)ToolFree
Shows how traces, nested observations and sessions map onto an agent run, in an open-source tool.
- Tracing (OpenAI Agents SDK docs) (opens in a new tab)DocsFree
Lists the span types an agent framework records: agent, generation, function, handoff and guardrail.
More for this topic
- Demystifying evals for AI agents (Anthropic) (opens in a new tab)ArticleFree
Explains tasks, graders and transcripts, and why reading transcripts is part of running evals.
- LangSmith observability documentation (opens in a new tab)DocsFree
Tracing, run inspection and turning production traces into datasets in a hosted tool.