Turn a Production LLM Failure into a Regression Eval That Holds
A support assistant quoted a superseded 45-day refund window, the stale document was deleted, and nothing stopped it happening again. This finale of the LLM and RAG Evaluation series turns that incident into a regression case: replaying against the index snapshot, scrubbing against the customer record with keyed pseudonyms, shrinking with delta debugging against a mechanism predicate, and grading with fixture-driven checks. Hidden sibling cases then reject a prompt hotfix and a newest-version fix that both pass the original incident.

On 14 October a support assistant told a customer on an annual plan that they had 45 days to request a refund. The refund policy had said 21 days since 1 September, when version 4 replaced version 3. The customer pressed thumbs-down, an engineer deleted the version 3 document from the index, and the ticket was closed as fixed. Nothing was added to the eval suite. When the policy changes again, nothing will notice whether the assistant follows it.
That ticket holds everything a regression case needs and none of it in usable form. The conversation contains a name, an email, an order number and a phone number. The index the assistant read from no longer exists. The thumbs-down says the customer was unhappy, not why. This final part of the LLM and RAG Evaluation series turns that incident into a case that fails for the right reason, stays in the suite, and does not reward a fix that only learned this one answer.
What has to be saved at the moment of failure?
Enough to make the same failure happen again on demand. For a retrieval-augmented assistant that is more than the conversation. NIST AI 600-1 suggests a minimum set of fields for incident reports (GV-4.3-002 includes system ID, title, reporter, data reported, date, description, impacts and stakeholders) and separately asks for procedures to "record and track GAI system reported errors, near-misses, and negative impacts" (MG-4.3-002). For an eval you also need what the system read. Here is the incident record after scrubbing, which is the only form that should leave the logging system:
{
"incident": "INC-0412", "trace_id": "tr_8c41f0", "ts": "2026-10-14T09:12:44Z",
"app": {"prompt_version": "support-v19", "model": "vendor-model-2026-06-01",
"system_fingerprint": "fp_3a9e", "temperature": 0.3, "top_k": 6,
"index_snapshot": "kb-2026-10-14"},
"retrieved": ["rp-v3-2", "rp-v4-2", "plan-1", "ret-v1-1", "cancel-1", "ret-v2-1"],
"answer_observed": "You can get a full refund within 45 days on an annual plan [rp-v3-2].",
"turns": "6 turns, scrubbed (see below)"
}
The app block is the arm manifest from the model upgrade part, recorded per request instead of per experiment. Two fields in it are easy to skip. model should be the ID the response reports, not the one in your config, because an alias resolves on the vendor's side. system_fingerprint is what OpenAI's Chat Completions API returns to describe "the backend configuration that the model runs with"; the same reference calls its seed parameter Beta and says determinism "is not guaranteed". So a replay is a sample, not a rerun, which matters for every step below.
The field that decides whether you can reproduce anything is index_snapshot. Replaying the whole scrubbed conversation through the incident build twenty times, first against the snapshot and then against today's index:
replay on snapshot kb-2026-10-14 : 17/20 fail
replay on today's index : 0/20 fail
Today's index no longer contains the version 3 chunk, because someone deleted it during the hotfix. Against it the bug cannot be reproduced, and a reviewer reading "0/20 fail" would conclude the case is wrong. Keep the retrieved chunk ids with their document versions, and keep the snapshot they came from (or the chunks themselves) for as long as the case lives.
How do you scrub a trace without breaking the case?
Pattern matching finds emails, phone numbers and order ids. It does not find names, and the assistant had greeted the customer by first name. The useful check is to compare the scrubbed case with the customer's own record, fetched from the CRM by trace id, instead of with the list of things the scrubber already found:
KEY = load_secret("eval-pseudonym-key") # kept in the secret store, never beside the cases
def pseudonym(kind, value):
tag = hmac.new(KEY, f"{kind}:{value}".encode(), hashlib.sha256).hexdigest()[:6]
return {"email": f"user-{tag}@example.invalid", "phone": f"+00 00000 {tag}",
"order": f"HB-{tag}", "amount": "1,000", "name": f"Customer {tag}"}[kind]
def sanitize(trace, known=None):
found, out = {}, json.loads(json.dumps(trace))
for t in out["turns"]:
hits = {v: ("name" if "name" in f else f) for f, v in (known or {}).items() if v in t["text"]}
for kind, pat in PATTERNS: # email, phone, order id, amount
hits.update({v: kind for v in re.findall(pat, t["text"])})
for v in sorted(hits, key=len, reverse=True):
found[v] = pseudonym(hits[v], v)
t["text"] = t["text"].replace(v, found[v])
out.pop("feedback")
return out, found
def residue(case, account):
blob = json.dumps(case)
return [v for v in account.values() if v in blob]
patterns only: replaced 4 | account values left: ['Priya Raman', 'Priya']
+ known values: replaced 6 | account values left: []
turn 0: Hi, this is Customer e9d6a6, account [email protected]
turn 1: Thanks Customer 81fb51, how can I help today?
turn 2: I bought the annual plan on 2 October, order HB-c27dd3, paid 1,000.
turn 5: Call me on +00 00000 0303c3 if that is easier.
Collect every span from the original text first and replace longest first. Replacing as you go lets the email pattern match the pseudonym just written and hash it a second time.
The keyed hash matters because a case has internal references. Turn 2 and turn 3 both mention the order; with a keyed pseudonym both become HB-c27dd3, so a case that depends on "the order the customer just mentioned" still works. The tempting shortcut, a plain SHA-256 of the value, is reversible by anyone holding a list of candidates:
leaked = hashlib.sha256(b"[email protected]").hexdigest() # what a plain-hash scrubber writes
crm_export = ["[email protected]", "[email protected]", "[email protected]"]
print([e for e in crm_export if hashlib.sha256(e.encode()).hexdigest() == leaked])
# ['[email protected]']
Keyed pseudonyms are still not anonymisation. The GDPR defines pseudonymisation as processing after which data cannot be attributed to a person "without the use of additional information, provided that such additional information is kept separately", and Recital 26 says pseudonymised data that could be re-attributed "should be considered to be information on an identifiable natural person". The key is that additional information. Store it where the production data lives, and treat the eval corpus as personal data until a reviewer has signed it off.
If you use Presidio for detection, read its hash operator's changelog note first. Since version 2.2.361 the operator uses a random salt per entity by default, so the same value gets different hashes in different entities and calls. That is safer against dictionary attacks and silently breaks the order-number property above unless you pass your own salt. Presidio is also now a community-governed project under the Data Privacy Stack organisation rather than a Microsoft one, so its documentation has moved to a new address.
The scrubber dropped the feedback field on purpose. The customer's comment was "agent later told me 21 days??", which happens to point at the bug. The next thumbs-down may sit on a correct 21-day answer from a customer who wanted 45. A reaction tells you where to look; the policy text tells you what the expected behaviour is.
What is the root cause when the right chunk was in the prompt?
Walk the trace through the ordered checks from the retrieval-versus-generation part. The gold evidence is chunk rp-v4-2. It is in the index, it scores, it ranks second inside top-6, and it reaches the prompt. By that ladder this is a generation failure, and the obvious next step is a prompt edit telling the model to prefer newer policies.
That ladder asks whether the gold chunk was lost. It does not ask whether a contradicting chunk that is no longer in force sat above it. Here rp-v3-2 ranked first because its wording ("you can request a full refund") shares more words with the question, and the index had no notion of a version being superseded. Give this its own label, stale-evidence, with its own check: does any chunk in the prompt have a superseded_on date on or before the trace date? The label sends the work to whoever owns ingestion, not whoever owns the prompt. NIST's MG-4.2-002 asks for post-mortem analyses "to understand the root causes and implement preventive measures", and a root cause that names the wrong owner prevents nothing.
How small should the case be, and what does shrinking throw away?
The scrubbed trace has six turns and six retrieved chunks. Most of them are irrelevant, and a twelve-element case is slow to read and fragile to maintain. Delta debugging (Zeller and Hildebrandt's ddmin) removes parts of the input while the failure persists and returns a 1-minimal input: removing any single remaining element makes the failure disappear. The Debugging Book chapter that implements it puts the cost at a number of tests logarithmic in the input length in good cases and quadratic in the worst, and adds a condition that LLM pipelines break: the test must be deterministic.
So the test is a vote. Each candidate subset is replayed ten times and counts as failing if at least six replays fail. Then the important decision is which predicate the vote applies to:
def k_of_n(trace, pred, n, k, tag, budget):
def test(subset):
hits = 0
for t in range(n):
budget[0] += 1
if pred(subset, replay_generator(trace, subset, t, tag)):
hits += 1
return hits >= k
return test
symptom = lambda s, a: "45 days" in a
mechanism = lambda s, a: "45 days" in a and ("chunk", "rp-v4-2") in s
symptom 12 -> 3 elements tests= 69 generator calls= 700 kept=[('turn', 2), ('turn', 4), ('chunk', 'rp-v3-2')]
mechanism 12 -> 4 elements tests= 79 generator calls= 800 kept=[('turn', 2), ('turn', 4), ('chunk', 'rp-v3-2'), ('chunk', 'rp-v4-2')]
Both runs kept the turn that says "annual plan" and the turn that asks the question, which is correct: without the first, the stub answers for a monthly plan. The symptom run also threw away the version 4 chunk. In a case whose only policy text says 45 days, answering 45 days is faithful to the context. That minimal case would fail every build that answers correctly from what it was given, and pass a build that ignores its context. The mechanism predicate keeps the conflict, which is what the incident was about. Write the predicate as the defect, not the bad string.
The vote costs real calls. Over 200 different seeds:
trials per test= 1 need=1: result sizes over 200 seeds {'start passed': 19, 3: 181} mean calls=68
trials per test=10 need=6: result sizes over 200 seeds {'start passed': 1, 3: 199} mean calls=700
With one replay per test, 19 of 200 attempts never started, because the full trace did not fail on its first replay and the team would have filed "cannot reproduce". When it did start, it reached the same three elements, since the stub's noise only produces false passes and ddmin tolerates those by trying another split. A model that also fails for unrelated reasons produces false fails, and those let ddmin keep a subset that does not carry the defect; this stub cannot show that, so test your own predicate's false-fail rate before trusting a shrink. The price of the vote is ten times the calls.
Which grader does this failure deserve?
The failure has a crisp signature: a number of days and a citation. That calls for code, not a model. The grader reads the expected values from the case, so a future policy change edits fixture data rather than the grader:
def grade(answer, item):
m = re.search(r"within (\d+) days", answer)
cite = re.search(r"\[([a-z0-9\-]+)\]", answer)
return float(bool(m) and m.group(1) == item["expected_days"]
and (cite is None or cite.group(1) == item["current_chunk"])
and not any(s in answer for s in item["must_not"]))
If your suite runs on OpenAI's graders, the obvious choice fails on the negative half. The string_check grader has four operations: eq, ne, like and ilike, where like means "contains". There is no "does not contain", and ne compares the whole string. (The graders guide's bullet list spells the second one neq; the API reference enumerates ne.) "Must not mention 45 days" therefore needs a Python grader, which receives the model output as sample and your data row as item:
{
"type": "python",
"name": "refund_window_in_force",
"source": "import re\n\ndef grade(sample, item):\n out = sample['output_text']\n m = re.search(r'within (\\d+) days', out)\n if not m or m.group(1) != item['expected_days']:\n return 0.0\n return 0.0 if any(s in out for s in item['must_not']) else 1.0\n",
"image_tag": "2025-05-08"
}
The guide limits that code to under 256 kB with no network access and two minutes of execution, which is ample for a regex. Reach for a model grader only when the expected behaviour is a judgement, such as whether an abstention message is clear or whether a summary of the policy is faithful. That grader then needs the calibration evidence from the judge calibration part. If the right behaviour for some sibling is to decline because no policy is in force, score it with the abstention and citation checks from the hallucination part, not with this one.
How do you stop a fix from memorising the incident?
Write the sibling cases before anyone touches the code, from the mechanism rather than from the wording. Each one changes something the incident held fixed:
| Case | What changes | Expected |
|---|---|---|
| pf-0412-a | Nothing: the minimised incident, index as on 14 October | 21 days, cites rp-v4-2 |
| pf-0412-b | The question, reworded ("refund deadline on my yearly plan") | 21 days |
| pf-0412-c | Time: version 5 (10 days) took effect on 1 December, asked on 5 December | 10 days, cites rp-v5-2 |
| pf-0412-d | The document: hardware returns, where version 2 (15 days) replaced version 1 (30) | 15 days, cites ret-v2-1 |
| pf-0412-e | Version 5 is announced but not yet in force on 14 October | 21 days, not 10 |
The developer fixing the bug sees case a. Cases b to e stay with the case owner until the fix is proposed. Three fixes went through all five, twenty replays each:
build a b c d e
incident 3/20 0/20 0/20 2/20 5/20
A: prompt hotfix 17/20 18/20 0/20 4/20 20/20
C: newest version 20/20 20/20 20/20 20/20 0/20
B: in force on as_of 20/20 20/20 20/20 20/20 20/20
Fix A adds "the annual plan refund window is 21 days" to the system prompt. It passes the incident most of the time, then fails the moment version 5 takes effect, and does nothing for hardware returns. Fix C, keep only the highest version of each document, looks complete until case e: it serves version 5 seven weeks before it applies. Only fix B, which keeps chunks whose effective_from is on or before the question date and whose superseded_on is later, passes all five. Without case e, fix C would have shipped.
Case e also shows why the expected value lives beside an as_of date and an index snapshot. The same question has three correct answers depending on the date, and a grader with "21" written into it would have been wrong for two of them.
These siblings differ from the attack variants in the red-teaming part. There a generator rewrites a breach many ways and keeps what gets through. Here a person writes four cases from the root-cause label, one per dimension the mechanism can vary on. A paraphrase generator would have produced more cases like b and never produced c, d or e. Keep at least one sibling out of anything used for prompt tuning, for the same reason the dataset part keeps a holdout.
What does the suite keep, and when can it drop it?
The suite keeps one record per incident, pointing at its case family. It holds no conversation text, only ids that resolve inside systems already allowed to hold it:
{
"incident": "INC-0412",
"trace": "tr_8c41f0",
"root_cause": "stale-evidence",
"cases": ["pf-0412-a", "pf-0412-b", "pf-0412-c", "pf-0412-d", "pf-0412-e"],
"hidden_from_fix_author": ["pf-0412-b", "pf-0412-c", "pf-0412-d", "pf-0412-e"],
"before": {"build": "incident", "pf-0412-a": "17/20 fail"},
"after": {"build": "B: in force on as_of", "all_cases": "100/100 pass"},
"privacy_review": {"by": "dpo-delegate", "on": "2026-10-16", "sanitiser": "v3", "key_id": "kp-2026-10"},
"owner": "kb-ingestion",
"retire_when": "index rejects chunks without effective_from and superseded_on; recorded with the PR"
}
Three rules keep the collection useful as it grows. Each new incident is checked against existing root-cause labels before a family is written. A fifth stale-refund case under stale-evidence adds minutes to every run and no coverage, while the first case of a new label is worth more than ten paraphrases. The before number must show the case failing on the incident build, or it does not reproduce anything. And a family retires only with a recorded reason, usually that the mechanism became impossible in code. "It has passed for six months" is not one: it passes because the fix works, and it is the only thing that will notice when a refactor removes the fix.
The suite guards builds; it cannot see a document uploaded on Friday without an effective date. A cheap production monitor covers that half, counting answers whose prompt contained a chunk that was not in force that day:
def superseded_in_context(trace, index):
day = trace["ts"][:10]
meta = {c["id"]: c for c in index}
return [cid for cid in trace["retrieved"]
if meta[cid]["superseded_on"] and meta[cid]["superseded_on"] <= day]
2026-10-14 ret-v1-1 1
2026-10-14 rp-v3-2 1
2026-12-03 rp-v4-2 1
On four sample log lines it flags the incident, the hardware-returns sibling that nobody had reported, and version 4 still being served after version 5 took effect. NIST's MS-2.7-006 suggests measuring "the rate at which recommendations from security checks and incidents are implemented". For this incident, a monitor that reads zero after the fix and stays at zero through the next policy change is the evidence that the recommendation was implemented and stayed implemented.
The eval files need the same version control as code. OWASP's data and model poisoning entry recommends data version control "to track changes in datasets and detect manipulation". It matters here because anyone who can file feedback can try to place a case in your suite. That is one more reason a person approves every case before it counts.
Where can a model help, and what must a person sign?
A model is good at the volume work: clustering a week of thumbs-down traces into candidate incidents, proposing redaction spans (Presidio's analyzer exists for this), and drafting sibling wording once a person has named the dimensions. OpenAI's evaluation guide asks teams to "log everything" so logs can be mined for eval cases, and to "grow the eval set over time"; the mining is where a model saves hours.
A person signs four things: that the scrubbed case leaks nothing (the residue check is evidence for that review, not a replacement), what the expected behaviour is, which root-cause label applies, and which siblings stay hidden. None of the raw trace goes into fine-tuning or few-shot examples. OWASP's sensitive information entry asks for sanitisation "to prevent user data from entering the training model", and the cheapest way to comply is never to put the raw trace where a training job can reach it.
How do the eight parts fit around one incident?
The series has been building the pieces this incident needs, in roughly the order it needs them:
| Step on INC-0412 | Where it is covered |
|---|---|
| Case record fields, risk slices, hash-assigned holdout | Build an LLM eval dataset from product risks |
| Trusting a model grader for the judgement cases | Calibrate LLM-as-judge scores |
| Localising the stage that lost or mis-ranked evidence | Retrieval versus generation failures |
| Whether the needed facts reach the prompt intact | Test RAG chunking with product questions |
| Citation support and when to decline | Hallucination, abstention and citations |
| Keeping deliberate breaches as permanent cases | Red-team LLM applications with abuse cases |
| Comparing builds with repeated runs and written budgets | Evaluate LLM model upgrades |
Every part assumed a case set that grows. This one is how it grows from what actually went wrong, rather than from what someone thought might.
Apply this now
Pick the most recent closed ticket where your assistant gave a wrong answer. Find its trace and check whether you can name the model ID returned, the prompt version and the exact chunks retrieved. If any is missing, adding it to the request log is today's change, and it costs less than any eval.
Then scrub that trace against the customer record and run a residue check, shrink it with a mechanism predicate and at least five replays per test, write the grader with expected values taken from fixture data, and write three siblings that vary time, document and wording. Run the family against the build from the incident date and against today's build.
Keep as evidence: the residue output showing zero account values, the ddmin output with its call count, the per-build pass table with the incident build failing, and the regression record with a named privacy reviewer and owner.
FAQ
What if the failure was reported but no trace was logged?
Rebuild the case from the report and mark its provenance as reconstructed. It can still guard against the mechanism, but its before number comes from your reconstruction, not from production, so label it that way in the record. Then fix the logging, because the next incident will be just as hard to rebuild.
Should every thumbs-down become an eval case?
No. A thumbs-down starts triage. Many sit on correct answers the user disliked, and many repeat a root cause that already has a family. A case is earned by a confirmed wrong behaviour with an expected behaviour someone with authority has written down.
Can I write a synthetic case and skip the production trace entirely?
For the case file, yes, and often you should: a hand-written case with invented values carries no personal data at all. Keep the link to the incident id so the case's provenance is auditable, and replay both the original trace and the synthetic case against the incident build several times, so you know they fail the same way.
How many replays per case once it is in the suite?
Enough that a fixed build and a broken build cannot be confused. In the table above the incident build passed case e five times in twenty, so a single replay would have reported it fixed a quarter of the time. Set the count from your noise floor, as the model upgrade part does for whole suites.
Primary references
- Generative AI Profile, NIST AI 600-1 (July 2024). GV-4.3-002 on minimum incident report fields, MG-4.3-002 on recording errors and near-misses, MG-4.2-002 on post-mortem root-cause analysis, MS-2.7-006 on measuring how quickly incident recommendations are implemented, and Appendix A.1.8 on logging, version history and metadata.
- Sensitive Information Disclosure, OWASP LLM02:2025. Sanitisation so user data does not enter training, and scrubbing or masking sensitive content before it is used.
- Data and Model Poisoning, OWASP LLM04:2025. Data version control to track dataset changes and detect manipulation, and the risk from unverified data.
- Regulation (EU) 2016/679, the GDPR, on EUR-Lex. Article 4(5), the definition of pseudonymisation with additional information kept separately, and Recital 26, that pseudonymised data which can be re-attributed is information on an identifiable person.
- Presidio Anonymizer documentation. The built-in operators, among them replace, redact, hash, mask, encrypt, custom and keep, and the 2.2.361 change to a random per-entity salt for the hash operator, which breaks referential integrity unless a salt is supplied.
- Presidio project transition update. That Presidio is now an independent, community-governed project under the Data Privacy Stack organisation, still MIT-licensed.
- Reducing Failure-Inducing Inputs, The Debugging Book. The ddmin algorithm and its 1-minimal result, logarithmic best case and quadratic worst case, and the condition that the test be deterministic and quick.
- Zeller and Hildebrandt, Simplifying and Isolating Failure-Inducing Input, IEEE TSE 28(2), 2002. The origin of delta debugging; bibliographic record checked, body not read.
- Graders guide, OpenAI API documentation. String check operations and their meanings, the Python grader's grade(sample, item) contract, the item and sample namespaces, and the 256 kB, no-network, two-minute limits.
- Graders API reference, OpenAI. The string check operation enumerated as eq, ne, like or ilike, which differs from the guide's neq spelling.
- Create chat completion, OpenAI API reference. The seed parameter as Beta and best-effort, and system_fingerprint as the backend configuration identifier.
- Evaluation best practices guide (OpenAI). "Log everything" to mine logs for eval cases, and continuous evaluation that runs on every change and grows the eval set.
LLM and RAG Evaluation
That is the last part of LLM and RAG Evaluation. Browse the other series