By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You tighten one instruction and the refund tickets get better. Two weeks later a customer is told to keep a $4,000 item. The edit that fixed the common case also removed the escalation rule for high-value orders. No test failed, because there was no test.
A prompt or a tool changes behaviour without changing a type. The compiler stays silent, the unit tests pass, and the regression reaches a customer. This lesson builds the smallest suite that catches that change. It then sets out what to do when a step fails inside a live request.
The useful answer is a fixture: one recorded high-value refund question, with the expected property stored beside it. The test asserts one thing, that a refund above the approval limit must set the escalate flag. It runs in milliseconds, costs nothing, and fails the moment the rule disappears.
Three words carry this lesson. A fixture is a saved input and its recorded model response, stored in the repository. A property is something that must hold for any good answer: a valid schema, an escalation flag, a cited order id. A check is the assertion that compares them.
Properties are the important part. You cannot assert that a model writes the same sentence twice, and you should not try. You can assert that the answer parses, names the right record, and takes the safe branch.
| Piece | What it holds | Why it survives a model change |
|---|---|---|
| Fixture | One input and the recorded response beside it | It is data, so it does not drift when the model does |
| Property | A rule any good answer obeys: schema, ids, flags, refusals | It describes intent, not wording |
| Check | A fast assertion over the fixture | It fails in seconds and names the property |
| Runner | pytest or any runner already wired into CI | The change cannot merge while a property is broken |
Do not invent cases at a whiteboard. Take them from traces you already have: one case per class, then the cases that cost you money.
Prose is hard to assert and easy to argue about. Tool arguments are JSON, so they are easy to assert. Pin the tool name, the arguments, the escalation flag and the error path. This suite replays recorded responses, so it needs no key and no network.
# A regression suite for a prompt and a tool.
# Run with: pytest -q tests/test_support_agent.py
# The client replays fixtures, so no API key is needed.
import pytest
from support_agent import FakeClient, SupportAgent
FIXTURES = {
"order_status": {
"question": "Where is order A17?",
"tool_name": "lookup_order",
"arguments": {"order_id": "A17"},
"answer": "Order A17 is on hold in the warehouse.",
},
"high_value_refund": {
"question": "Refund order B02, it cost 4000.",
"tool_name": "issue_refund",
"arguments": {"order_id": "B02", "amount": 4000},
"answer": "I have escalated this refund for approval.",
"must_escalate": True,
},
}
def replayed(case):
return FakeClient(
[
{"stop_reason": "tool_use", "tool": case["tool_name"], "arguments": case["arguments"]},
{"stop_reason": "end_turn", "text": case["answer"]},
]
)
@pytest.mark.parametrize("name", sorted(FIXTURES))
def test_tool_arguments_are_exact(name):
case = FIXTURES[name]
result = SupportAgent(client=replayed(case)).run(case["question"])
assert result.tool_calls[0].name == case["tool_name"]
assert result.tool_calls[0].arguments == case["arguments"]
def test_high_value_refund_escalates():
case = FIXTURES["high_value_refund"]
result = SupportAgent(client=replayed(case)).run(case["question"])
assert result.escalated is TrueRead the assertions as the contract. The first test pins the tool name and the exact arguments, so a prompt edit that starts guessing order ids fails. The second pins the escalation property that the missing rule would have broken. Neither compares a sentence.
A class tells you what failed. Recovery is a separate decision, and the worst option is usually a blind retry. Four moves cover the cases you will meet, and the class picks between them.
| Move | Use it when | What it costs |
|---|---|---|
| Retry with backoff | The class is transport and the error is transient | Latency, plus a capped attempt budget |
| Repair the input | The class is request shape or tool arguments | One extra call, and a validator you maintain |
| Reduce the ask | The context is too long or the output too complex | A smaller answer that still meets the requirement |
| Escalate and fail closed | The stakes are high, or the class is data | A person in the loop, and an honest message |
Every move needs a cap. Retry at most three times with jitter. Repair at most once, because a model that fails twice usually fails the same way. Escalate with the trace attached, not a summary.
A suite that takes twenty minutes does not run on every commit. Keep it under a minute with three disciplines.
Then add the release rule: no prompt, tool or model change ships without the suite green. The suite is not evidence for a review meeting; it is the gate that stops a regression at the pull request.
Write the test that would have caught the escalation regression in the opening story.
Copy one real trace into a fixture file, and record the property you expect beside it.
Write one assertion for that property. If you need two assertions, you have two tests.
Break the rule on purpose: set the escalate flag to false in a copy and confirm the test fails.
Restore the code, run the suite, and time it. If it takes over a minute, replay more and call less.
Key takeaways
A fixture plus a property plus a check is a regression test; exact wording is not.
Build fixtures from real traces and real incidents, one per class and per tool.
Assert tool names, arguments, escalation flags and error paths, not sentences.
Recovery is a decision with a cap: retry, repair, reduce the ask, or escalate.
A regression suite is a merge gate, and it has to run in under a minute.
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.