Sub topic 15
Keep the Dataset Alive with Production Failures
This chapter assumes you already have a tagged JSONL dataset with a case schema, a dev/test split by hashed id, and version numbers. It also assumes you can run an eval and read per-slice scores. Here you will learn how to feed real failures back into that dataset without breaking it.
Why a finished dataset goes stale
A dataset is a snapshot of what you expected users to do. Three things move away from it over time:
- Users ask new kinds of questions, such as a new product line or a new phrasing habit.
- The product changes. A policy, a tool, or a document set is updated, and some references become wrong.
- The model or prompt improves until the old cases all pass. Scores saturate and stop telling you anything.
Production traffic is the only free source of cases that reflect current reality. Maintenance means turning that traffic into labeled cases in a controlled way.
The maintenance loop
Each step has a way to go wrong, so the sections below take them in order.
Capture failure signals
Useful signals include:
- Thumbs-down ratings and user complaints.
- A user rephrasing the same question right away.
- Handoffs to a human agent.
- Guardrail triggers, timeouts, and tool errors.
- Low scores from an LLM judge run on a sample of traffic.
- Support tickets that mention the assistant.
Do not collect only failures. A dataset made entirely of past failures overstates how often the app fails, and it says nothing about new kinds of input. Also sample a small slice of random recent traffic each cycle, for example 20 cases a week, and label it whether or not it looked bad. Tag it fresh_sample. It is your drift detector.
Triage before you add anything
Not every bad output is a good test case. For each candidate, decide which of these it is:
| Finding | Action |
|---|---|
| App error that reproduces from the input alone | Add as a case |
| Failure that depended on hidden state (session history, time of day) | Add only if you can put that state in the input |
| Ambiguous question where experts would disagree | Fix the task definition or add a rubric, then add |
| Dataset or reference was wrong | Correct the existing case and record the fix |
| Out of scope for the product | Discard and log the reason |
| Infrastructure outage | Discard |
Cluster similar failures before adding them. Ten paraphrases of one bug should not become ten cases. They would swamp a slice and can also straddle the dev/test boundary (see below).
Promote a failure to a case
The script below turns one log record into an unlabeled case. It removes email addresses, derives a stable id from the normalized input so the same question is never added twice, and marks the case needs_label.
import hashlib
import json
import re
from datetime import date
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
def scrub(text):
return EMAIL.sub("[EMAIL]", text)
def case_id_for(text):
normalized = " ".join(text.lower().split())
digest = hashlib.sha256(normalized.encode("utf-8")).hexdigest()
return "prod-" + digest[:10]
def load_ids(path):
try:
with open(path, encoding="utf-8") as f:
return {json.loads(line)["id"] for line in f if line.strip()}
except FileNotFoundError:
return set()
def promote(record, path, known_ids):
text = scrub(record["user_input"])
cid = case_id_for(text)
if cid in known_ids:
return None
case = {
"id": cid,
"input": text,
"reference": None,
"tags": record.get("tags", []) + ["regression"],
"source": "production_log",
"difficulty": "unknown",
"status": "needs_label",
"added": date.today().isoformat(),
}
with open(path, "a", encoding="utf-8") as f:
f.write(json.dumps(case) + "\n")
known_ids.add(cid)
return case
def ready_cases(cases):
return [c for c in cases if c.get("status", "labeled") == "labeled"]
if __name__ == "__main__":
path = "cases.jsonl"
known = load_ids(path)
record = {
"user_input": "Can I return a laptop bought by [email protected] after 45 days?",
"tags": ["returns"],
}
print(promote(record, path, known))Run it twice. The second call returns None because the id already exists.
The ready_cases helper matters. A case with reference set to None would crash the exact-match grade function from earlier. A half-labeled case that does get scored silently counts as a failure. Filter on status before every run.
Label with the source of truth
For a failure case, never copy the app's wrong answer as the reference, and do not accept the app's corrected answer without checking it. Have an expert write the reference from the authoritative source, such as the policy page or the product database. Record who labeled it and when. For open-ended tasks, write a rubric instead of one reference string.
Production cases tend to be the hard, ambiguous ones, so check labeling quality here more than on easy synthetic cases. Have a second person label a sample of each batch and compute Cohen's kappa. If agreement is low, the task definition needs work before more cases are added.
Protect the dev/test split
Failures are the cases you are most tempted to fix, and that is how a test set gets contaminated. Follow these rules:
- Assign the split by hash, as before, so no one chooses where a case goes.
- Debug and tune against dev cases only. If you read a test failure to understand a bug, treat that test case as burned and replace it later.
- Keep paraphrases of one failure in the same split. If you cluster failures, hash the cluster id instead of the case id. Otherwise a fix tuned on a dev paraphrase will pass its twin in test, and the test score will be optimistic.
- Check each new case for near-duplicates against the test set. An exact-hash check only catches identical text.
Version every change
Adding cases changes the score even if the app did not change. Treat dataset edits like code releases:
| Change | Version bump | Comparing scores across versions |
|---|---|---|
| Add cases | Minor | Compare only on the shared cases |
| Fix a wrong reference | Patch | Rerun the previous app version |
| Change rubric or schema | Major | Do not compare |
| Retire cases | Minor | Compare only on the shared cases |
Keep a changelog with the date, the number of cases added, and their source. When you report a result, include the dataset version next to the score. To measure whether a fix helped, run the old and new app on the same dataset version. Do not change both in one run.
Keep the dataset healthy
Regression cases accumulate and can crowd out everything else. Review these each cycle:
- Slice weights. Report
regressionandfresh_sampleas separate slices from the overall score. A rising regression pass rate shows fixes are holding. A fallingfresh_samplerate shows the dataset is drifting from reality. - Stale references. When a policy changes, for example the return window moves from 30 to 60 days, find every case that depends on it by tag and update or retire it.
- Retirement. Mark cases
retiredwith a reason instead of deleting them, so old results stay reproducible. Move cases that have passed for many versions into a fast smoke set if you need quick checks. - Size. After adding cases, recompute the bootstrap interval on key slices. A new slice with 8 cases has an interval too wide to act on.
Common errors
- Adding only failures, so the dataset no longer represents normal traffic.
- Scoring
needs_labelcases. - Using the model's own output as the reference.
- Tuning on test cases that came from production.
- Letting old references go stale after a product change.
- Comparing scores from different dataset versions as if they were the same measurement.
- Storing raw logs with personal data in the dataset repository.
Exercise
A teammate adds 40 failure cases from last week's thumbs-down ratings and reports that accuracy dropped from 91% to 78%. The app did not change. What are two reasons this number is not a fair measure of a regression, and what would you report instead?
Show answer
First, the new cases were selected because they failed, so they are biased toward failure and will lower accuracy no matter how the app behaves. Second, the dataset version changed, so the two scores come from different case sets. Report the score on the unchanged old cases (still 91%), the score on the new regression slice separately, and a score on a random fresh_sample slice to estimate real-world accuracy. Include the dataset version with each number.
Exercise
A production case has the input "Can I return a laptop after 45 days?" and the app answered "Yes, within 60 days." Which of these is the right reference: the app's answer, or a value from the policy source? What field value keeps this case out of scoring until the reference exists?
Show answer
The reference must come from the policy source, written by an expert (here, "No. Returns are accepted within 30 days of delivery."). The app's answer is the failure being tested. Set status to needs_label and filter with ready_cases before each run so the case is skipped until the reference exists.