Sub topic 15
Keep the dataset alive with production failures
This chapter assumes you have a JSONL dataset with the case schema, tags, and dev/test split from earlier chapters, and that you can read per-slice scores. A dataset built once goes stale. Users change how they phrase requests, policies change, and the app gets new features. Production failures are the cheapest source of new cases, because they show inputs your dataset did not anticipate.
The maintenance loop
Each failure goes through the same steps. You find it, decide whether it is a real failure, label it, add it, and check that the score moves.
Find candidates
Useful signals include thumbs-down ratings, user retries, escalations to a human, and outputs that fail a cheap automatic check, such as invalid JSON. You can also sample a small random batch of ordinary traffic each week. Random samples catch failures that no signal flagged.
Triage each candidate before it enters the dataset. Ask three questions:
- Is the output actually wrong, or did the user just dislike it?
- Is the input one you would want the app to handle?
- Is it already covered by an existing case or a near-duplicate?
Turn a failure into a case
Write the reference answer yourself or have an expert write it. Do not copy the app's output as the reference, because that would make the failing answer count as correct. Record where the case came from so you can later compare slices by source.
import hashlib
import json
def split_for(case_id, test_percent=20):
digest = hashlib.sha256(case_id.encode("utf-8")).hexdigest()
return "test" if int(digest, 16) % 100 < test_percent else "dev"
def add_failure(path, user_input, reference, tags):
case_id = "prod-" + hashlib.sha256(user_input.encode("utf-8")).hexdigest()[:8]
try:
with open(path, encoding="utf-8") as f:
existing = {json.loads(line)["id"] for line in f if line.strip()}
except FileNotFoundError:
existing = set()
if case_id in existing:
return None # already in the dataset
case = {
"id": case_id,
"input": user_input,
"reference": reference,
"tags": tags + ["from_failure"],
"source": "production_log",
"difficulty": "hard",
}
with open(path, "a", encoding="utf-8") as f:
f.write(json.dumps(case) + "\n")
return case_id, split_for(case_id)The id comes from a hash of the input, so reporting the same failure twice produces the same id and the duplicate is skipped. The returned split comes from the same hash rule as before, so the new case lands in dev or test deterministically.
Keep the dataset honest
Adding cases changes the dataset, so treat each batch as a new version. Three habits keep it trustworthy.
- Protect the test split. Fix the app using dev cases. If you tune against a failure that sits in the test split, the test score stops measuring unseen data. Consider reserving new failures for dev first and promoting some to test later.
- Report the failure slice separately. The
from_failuretag gives you a score for cases the app has already failed on. Mixing these into the overall average makes old and new versions harder to compare. When you compare two versions, run both on the same dataset version. - Remove cases that no longer apply. If a policy changes, such as the return window going from 30 to 45 days, update the reference or retire the case. Record the change in the version notes instead of silently editing the file.
Common errors
| Error | Effect | Fix |
|---|---|---|
| Using the app's wrong output as the reference | The failure scores as a pass | Write the reference independently |
| Adding every thumbs-down | Noise and subjective cases | Triage first |
| Fixing the app on test-split cases | Inflated test score | Fix against dev only |
| Editing old cases without a version note | Scores across versions are not comparable | Bump the version and log the change |
Exercise
A user reports that your app wrongly said a laptop could be returned after 45 days. You add this input to the dataset and, to save time, paste the app's answer into the reference field. What goes wrong, and what should you do instead?
Show answer
The reference now contains the wrong answer, so the app scores a pass on the very case it fails, and the dataset hides the bug. Write the correct reference from the policy ("No. Returns are accepted within 30 days of delivery."), tag the case from_failure, set the source to production_log, and let the hash-based split place it in dev or test.