Sub topic 12
Maintaining datasets and updating baselines
A regression suite is only useful while its cases and its baseline match the product you ship. This chapter covers how to keep both current. It assumes you have a JSONL golden dataset, a pass-rate gate like the one from the earlier chapters, and a CI workflow that runs pytest evals. You should also be comfortable with Git pull requests and short Python scripts.
Why datasets and baselines decay
Three things go stale over time.
- The product changes. New features add inputs the dataset never covered. Old features get removed, and their cases now test behavior nobody wants.
- The world changes. Cases that mention dates, prices, product names, or policies become wrong even if the model is fine.
- The suite gets overfit. If people tune prompts until the golden cases pass, the suite measures how well the prompt fits those cases. It no longer measures how well the prompt works on real traffic.
The baseline decays differently. It is a number, such as 94% passing, that only means something for one dataset, one prompt, and one model. Change any of them and the number no longer describes the thing you are comparing against.
Maintenance has two goals. Every change to the dataset or baseline should be deliberate and reviewable. A baseline should never move because someone wanted a red build to turn green.
Treat the dataset as versioned code
Keep the dataset in the same repository as the prompts, and change it only through pull requests. Reviewers can then see what changed and why. Give every case enough metadata to support maintenance:
{"id": "refund-017", "input": "I was charged twice for order 4411", "required_keys": ["intent", "reply"], "must_contain": ["refund"], "status": "active", "added_on": "2026-11-03", "source": "production-incident-212", "tags": ["billing", "adversarial"]}The fields that matter most for maintenance:
| Field | Purpose |
|---|---|
| `id` | Stable identifier. Never reuse an id for a different case. Baselines and failure reports refer to it. |
| `status` | `active`, `quarantined`, or `retired`. Only `active` cases count toward the gate. |
| `added_on` | Lets you see how old a case is and how the dataset grows. |
| `source` | Where the case came from: a production incident, a support ticket, a hand-written edge case. This tells reviewers whether the case is still relevant. |
| `tags` | Lets you report pass rates per category, so a drop in one area is not averaged away. |
The test file from the dataset chapter loads every line. With statuses, it should skip the cases that are not active:
CASES = [
case
for case in (json.loads(line) for line in lines if line.strip())
if case.get("status", "active") == "active"
]Quarantined and retired cases stay in the file. Deleting them erases the history of why they existed.
Validate the dataset itself
Dataset files break in dull ways: a duplicate id, a missing key, a trailing comma that makes a line invalid JSON. Catch these in CI before any model call is made, because they cost nothing to check. Save this as evals/validate_dataset.py:
import hashlib
import json
import sys
from pathlib import Path
REQUIRED = {"id", "input", "required_keys", "status", "added_on", "source"}
STATUSES = {"active", "quarantined", "retired"}
def load_cases(path):
cases = []
text = Path(path).read_text(encoding="utf-8")
for number, line in enumerate(text.splitlines(), start=1):
if not line.strip():
continue
try:
cases.append(json.loads(line))
except json.JSONDecodeError as exc:
raise ValueError(f"line {number}: invalid JSON ({exc})") from exc
return cases
def validate(cases):
errors = []
seen = set()
for case in cases:
case_id = case.get("id", "<no id>")
missing = REQUIRED - set(case)
if missing:
errors.append(f"{case_id}: missing fields {sorted(missing)}")
if case_id in seen:
errors.append(f"{case_id}: duplicate id")
seen.add(case_id)
if case.get("status") not in STATUSES:
errors.append(f"{case_id}: status must be one of {sorted(STATUSES)}")
return errors
def dataset_hash(path):
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
if __name__ == "__main__":
dataset_path = sys.argv[1] if len(sys.argv) > 1 else "evals/cases.jsonl"
problems = validate(load_cases(dataset_path))
for problem in problems:
print(problem)
sys.exit(1 if problems else 0)The dataset_hash function is used later. It fingerprints the exact bytes of the file, so any edit changes the hash, including whitespace edits. That strictness is useful here.
Growing the dataset from real failures
The best new cases come from things that already went wrong. When a user reports a bad answer, or monitoring catches one, follow a fixed routine:
- Reproduce the failure with the current prompt and model.
- Reduce the input to the smallest version that still fails. Remove personal data and secrets.
- Write the check that the output should have passed.
- Add the case with
sourcepointing to the incident. - Confirm the case fails before the fix and passes after it.
Step 5 is the same discipline as a bug-fix test in ordinary code. A case that never failed proves nothing.
Add adversarial and boundary cases on purpose: empty input, very long input, a different language, prompt-injection text inside user content, and requests the feature should refuse. Tag them so you can report on them separately.
Keep the dataset balanced. If 80% of new cases come from one noisy incident category, the overall pass rate will mostly reflect that category. Review the tag counts every quarter or so.
Guard against overfitting
If you tune a prompt by looking at failing golden cases, the dataset stops being independent evidence. Two habits reduce this:
- Keep a holdout split, a set of cases tagged
holdoutthat nobody uses while editing prompts. Run it on the scheduled suite and compare its pass rate with the main set. A growing gap suggests overfitting. - Treat each case added after a prompt fix as part of the fix. It protects against that failure returning. It does not tell you how well the prompt does in general.
Retiring and quarantining cases
A failing case is not always a bad model. Sometimes the case is wrong. Use a different response for each situation:
| Situation | Action |
|---|---|
| The case fails on every run and the output is truly wrong | Fix the prompt or code. Do not touch the case. |
| The expected behavior changed on purpose (new policy, new format) | Edit the case in the same pull request as the behavior change, and state it in the description. |
| The case fails intermittently with no change on your side | Set `status` to `quarantined`, open a ticket, and investigate. |
| The feature or scenario no longer exists | Set `status` to `retired`. |
| Two cases test the same thing | Retire the weaker one. |
Quarantine is a temporary state. Without a deadline, it turns into a dumping ground where inconvenient cases disappear. Put the ticket id in the case (a note field works) and review the quarantined list during every dataset review. Report the quarantined count in the CI summary, so a rising number stays visible.
Updating baselines deliberately
The baseline file records what "normal" looked like when someone last approved it. Store enough context to know whether a comparison is still valid. A file such as evals/baseline.json:
{
"dataset_sha256": "3b1f...e9",
"case_count": 118,
"model": "example-model-2026-10-15",
"pass_rate": 0.94,
"updated_at": "2026-11-20",
"reason": "Added 6 billing cases from incident 212; prompt v14"
}The model value is a placeholder. Use the exact pinned model identifier from your provider.
When a baseline update is legitimate
Update the baseline when one of these happens, and say which in the pull request:
- Dataset changed. Adding, retiring, or editing cases changes what the pass rate measures. Recompute the baseline on the new dataset using the current main branch.
- Model or prompt change was approved on purpose. For example, you moved to a newer model and the pass rate changed in a way you accept. Record the trade-off, such as slightly lower on one tag and better latency.
- Genuine improvement. The pass rate went up and you want the gate to protect the gain.
Do not update the baseline because the build failed and the failure is annoying. A failed gate means someone should investigate.
Raising the baseline is cheap, lowering it needs a reason
A useful rule is a ratchet. The baseline can rise freely, but lowering it requires an explicit flag and a written reason. Save this as evals/update_baseline.py:
import argparse
import json
from datetime import date
from pathlib import Path
from validate_dataset import dataset_hash
BASELINE_PATH = Path("evals/baseline.json")
DATASET_PATH = "evals/cases.jsonl"
def main():
parser = argparse.ArgumentParser(description="Write a new eval baseline")
parser.add_argument("--pass-rate", type=float, required=True)
parser.add_argument("--case-count", type=int, required=True)
parser.add_argument("--model", required=True)
parser.add_argument("--reason", required=True)
parser.add_argument("--allow-lower", action="store_true")
args = parser.parse_args()
if BASELINE_PATH.exists():
old = json.loads(BASELINE_PATH.read_text(encoding="utf-8"))
if args.pass_rate < old["pass_rate"] and not args.allow_lower:
raise SystemExit(
f"New pass rate {args.pass_rate:.2%} is lower than "
f"{old['pass_rate']:.2%}. Re-run with --allow-lower and a "
"reason if this is intended."
)
baseline = {
"dataset_sha256": dataset_hash(DATASET_PATH),
"case_count": args.case_count,
"model": args.model,
"pass_rate": round(args.pass_rate, 4),
"updated_at": date.today().isoformat(),
"reason": args.reason,
}
BASELINE_PATH.write_text(json.dumps(baseline, indent=2) + "\n", encoding="utf-8")
print(f"Wrote {BASELINE_PATH}")
if __name__ == "__main__":
main()Run it from the repository root, for example python evals/update_baseline.py --pass-rate 0.94 --case-count 118 --model example-model-2026-10-15 --reason "Added billing cases". The result is a normal file change in the pull request, so the diff shows reviewers exactly which numbers moved.
Detect a stale baseline in CI
Add a check to the gate from the earlier chapter. If the dataset hash differs from the one recorded in the baseline, the comparison is not valid, and the build should say so instead of reporting a confusing pass-rate drop:
import json
from pathlib import Path
from validate_dataset import dataset_hash
def check_baseline_current(baseline_path="evals/baseline.json",
dataset_path="evals/cases.jsonl"):
baseline = json.loads(Path(baseline_path).read_text(encoding="utf-8"))
if baseline["dataset_sha256"] != dataset_hash(dataset_path):
raise SystemExit(
"Dataset changed but baseline.json was not updated. "
"Recompute the baseline and commit it with the dataset change."
)
return baselineThis forces dataset and baseline changes into the same pull request. A reviewer then sees both halves of the decision together.
The maintenance workflow
The diagram shows how a change moves through review.
Scheduled review
Put a recurring review on the calendar, monthly or quarterly depending on how fast the product moves. Use the scheduled CI run's report as input and check:
- Which cases have been quarantined longest?
- Which tags have the lowest pass rate, and is that a real weakness or a poor case?
- Which cases always pass? A case that has passed through many prompt and model changes is either an easy sanity check or too weak to detect anything. Keep a few sanity checks and tighten the rest.
- Does the dataset reflect current traffic? Sample recent real inputs and compare their types with the tag distribution.
- Is the holdout pass rate close to the main set?
- If you use a judge-based check, re-run the human-labeled calibration set. Judge agreement can shift when the judge model changes.
Common mistakes
- Updating the baseline from a local run. Local machines may use different model settings or versions. Compute baselines in CI, or in an environment that matches it.
- Changing the dataset and the prompt in one pull request without separating the effects. If the pass rate moves, you cannot tell which change caused it. Make the dataset change first, record the new baseline, then change the prompt.
- Reusing ids. A baseline that says
refund-017regressed is misleading if that id now refers to a different case. - Letting quarantine grow. A suite that skips 15% of its cases is not guarding what you think it is.
- Storing personal data in cases. Production examples must be anonymized before they enter the repository, since the dataset is visible to everyone with repository access and is sent to the model provider on every run.
Exercise
A pull request adds 10 new cases from a production incident and also edits the prompt. The pass rate in CI is 91%, and the old baseline is 94%. What is wrong with how this pull request is structured, and how would you restructure it?
Show answer
The dataset change and the prompt change are combined, so the drop could come from the new cases (which may be harder), from the prompt edit, or from both. The old baseline also no longer applies, because the dataset hash changed. Split it into two steps. First, add the 10 cases on the existing prompt, run the suite, and commit a new baseline that reflects the new dataset (new cases that fail show the incident is still unfixed). Then, in a second pull request, change the prompt and compare against that new baseline.
Exercise
A case fails about one run in five with no code changes. A teammate proposes deleting it so the build stays green. What do you do instead, and what must you record?
Show answer
Set the case's status to quarantined so it no longer counts toward the gate, and open a ticket with a deadline. Keep the case in the file. Record the ticket id and the date in the case or the changelog, and show the quarantined count in the CI report. Then investigate whether the case is ambiguous (fix the expected check), whether the model is genuinely unstable on this input (handle it with repeated runs, as in the nondeterminism chapter), or whether it should be retired.
Exercise
The baseline records dataset_sha256. Name one failure it prevents and one thing it cannot tell you.
Show answer
It prevents comparing a new pass rate against a baseline computed on a different dataset, because CI fails with a stale-baseline message when the hashes differ. It cannot tell you whether the dataset is good, because the hash only says the file changed or did not. It also does not detect that the model or prompt changed, which is why the baseline stores the model identifier and reason as well.