Sub topic 7
Baselines and pass thresholds
This chapter assumes you can write pytest tests, you have a golden dataset in JSONL, and you know that LLM output varies between runs. Earlier chapters covered deterministic checks, judge-based checks, and repeated runs. Here you will turn those results into a decision: does this change pass or fail?
Why a single assertion is not enough
A conventional unit test asserts one fact, and any failure is a bug. A prompt suite works differently. With 100 cases, a healthy prompt may fail three of them on one run and five on the next, because sampling is random and some cases sit near the edge of what the model can do.
If you require every case to pass, the suite fails at random and people stop trusting it. If you ignore failures, a real regression slips through. A baseline and a threshold solve this. They move the question from "did every case pass?" to "is the pass rate meaningfully worse than it was?"
- A baseline is a recorded measurement of how the current, accepted version of the system performs.
- A threshold is the rule that turns a new measurement into pass or fail.
Choosing what to measure
Pick metrics that match how the feature fails in production. Common choices:
| Metric | What it measures | Good for |
|---|---|---|
| Overall pass rate | Share of cases where all checks pass | A single headline gate |
| Per-check pass rate | Share passing one check, such as valid JSON | Finding which kind of failure grew |
| Per-category pass rate | Pass rate within a slice such as "adversarial" | Catching a regression hidden by an average |
| Mean judge score | Average rubric score from a judge | Quality that is not pass or fail |
| Critical-case failures | Count of failures in must-pass cases | Safety and contract cases |
An overall average can hide a real problem. Suppose 90 of your 100 cases are easy and 10 are adversarial. If the adversarial pass rate falls from 90% to 30%, the overall rate drops only from 90% to 84%. A 2% tolerance on the overall rate would flag this, but a 10% tolerance would not. Gate on slices that matter, not only on the total.
Recording a baseline
Store the baseline as a small file in the repository, next to the dataset. Because it is versioned, a change to the baseline shows up in a pull request and gets reviewed like code.
{
"model": "example-model-2025-06-01",
"prompt_version": "summarize-v7",
"dataset_version": "cases-v12",
"runs_per_case": 3,
"overall": 0.91,
"by_category": {
"typical": 0.96,
"edge": 0.88,
"adversarial": 0.80
}
}Record the model, prompt version, and dataset version with the numbers. A baseline is only comparable to a run that used the same dataset. If the dataset changed, the numbers measure different things, and you must re-measure before comparing (see the last section of this chapter).
Computing pass rates per category
The next script reads per-case results, computes the overall rate and the rate per category, and compares each with the baseline. It assumes each result is a dict with category and passed fields, which your test harness can write to a JSON file.
import json
import sys
from collections import defaultdict
from pathlib import Path
def pass_rate(results):
return sum(1 for r in results if r["passed"]) / len(results)
def by_category(results):
groups = defaultdict(list)
for r in results:
groups[r["category"]].append(r)
return {name: pass_rate(rs) for name, rs in groups.items()}
def compare(results, baseline, tolerance=0.02, category_tolerance=0.05):
problems = []
overall = pass_rate(results)
if overall < baseline["overall"] - tolerance:
problems.append(
f"overall {overall:.2%} < baseline {baseline['overall']:.2%} "
f"- {tolerance:.0%}"
)
current = by_category(results)
for name, base_rate in baseline["by_category"].items():
rate = current.get(name)
if rate is None:
problems.append(f"category '{name}' has no results")
elif rate < base_rate - category_tolerance:
problems.append(
f"{name} {rate:.2%} < baseline {base_rate:.2%} "
f"- {category_tolerance:.0%}"
)
return problems
if __name__ == "__main__":
results = json.loads(Path("evals/results.json").read_text(encoding="utf-8"))
baseline = json.loads(Path("evals/baseline.json").read_text(encoding="utf-8"))
problems = compare(results, baseline)
for p in problems:
print("FAIL:", p)
sys.exit(1 if problems else 0)Note the check for a missing category. Without it, deleting every adversarial case would make the suite look healthy.
Setting the tolerance
The tolerance is the drop you accept before failing. Too small and noise causes false alarms. Too large and real regressions pass.
You can estimate the noise instead of guessing. Run the unchanged system several times, for example 10, and record the overall pass rate each time. Then look at the spread.
import statistics
rates = [0.91, 0.89, 0.92, 0.90, 0.93, 0.88, 0.91, 0.92, 0.90, 0.91]
mean = statistics.mean(rates)
spread = statistics.stdev(rates)
print(f"mean={mean:.3f} stdev={spread:.3f}")
print(f"suggested tolerance (2 stdev): {2 * spread:.3f}")A tolerance of about two standard deviations of the run-to-run noise means a healthy system rarely fails the gate by chance. This is a rule of thumb, not a guarantee. Rerun the estimate whenever you change the dataset size, the number of runs per case, or the model.
Sample size matters. With 20 cases, one case flipping moves the pass rate by 5 points. A 2% tolerance on 20 cases means any single failure triggers the gate. With 20 cases you can only detect large regressions, so either add cases or use a wider tolerance and say so in the project documentation.
Hard gates and soft gates
Not every case deserves a percentage. Split your checks into two kinds.
- Hard gates must always pass. Examples: the output parses as JSON, no secret appears in the output, a refusal case does refuse. Any failure fails the build, with no tolerance.
- Soft gates are compared with the baseline using a tolerance. Examples: a style rubric, completeness of a summary, or a judge score.
Tag cases in the dataset with a critical field so the harness can enforce this. A rule such as "zero failures among critical cases, and overall within tolerance of baseline" is easy to explain and hard to game.
When a hard gate involves a nondeterministic case, decide how many repeats must pass. For a safety case, a common rule is that all repeats must pass, because one unsafe output in three is still unsafe. For a style case, a majority of repeats may be enough.
Absolute floors versus relative baselines
A relative check ("no worse than baseline minus tolerance") has a weakness. If you accept many small drops, each within tolerance, the baseline slowly slides down. After ten releases the system is far worse than it was, and every release passed.
Add an absolute floor, a minimum pass rate below which the build always fails, whatever the baseline says.
FLOOR = 0.85
def check_floor_and_baseline(current, baseline, tolerance=0.02, floor=FLOOR):
if current < floor:
raise SystemExit(f"Pass rate {current:.2%} is below floor {floor:.0%}")
if current < baseline - tolerance:
raise SystemExit(
f"Pass rate {current:.2%} is below baseline {baseline:.2%} "
f"minus tolerance {tolerance:.0%}"
)The floor expresses a product decision ("we will not ship below 85%"). The baseline expresses a engineering one ("do not get worse than last time"). You need both.
One-sided checks and improvements
The checks above fail only when the pass rate falls. A large jump upward deserves attention too, but it should not fail the build. Print a notice when the rate exceeds baseline plus tolerance, and let a person decide whether to raise the baseline. A sudden jump can mean an improvement, but it can also mean cases became easier, a check became looser, or a bug made a check always pass.
Deciding when to update the baseline
The baseline should change only on purpose. A good process:
- A change lowers or raises the pass rate and the gate reports it.
- A reviewer reads the failing cases, using the triage steps from the reporting chapter.
- If the drop is an accepted trade-off, such as a cheaper model with slightly lower quality, the author updates
baseline.jsonin the same pull request and explains why. - A second reviewer approves the baseline diff.
Never update the baseline automatically after a green run on the main branch. Automatic updates let the baseline ratchet downward without anyone deciding to accept the loss. If you want automation, update the baseline only upward, and only through a pull request.
When the dataset changes, re-measure the baseline on the old and the new prompt version using the new dataset. Compare like with like. If you only change the dataset and the baseline together, you cannot tell whether the system got worse or the new cases are harder.
flowchart TDThe diagram below summarizes the decision flow of a gate run.
Common mistakes
- Setting the tolerance by feel. Measure run-to-run noise first.
- Gating only on the average. Add per-category checks and hard gates.
- Comparing runs with different datasets. Version the dataset and store its version in the baseline.
- Letting the baseline slide. Use a floor and require a reviewed pull request for baseline changes.
- Treating a small suite as precise. With few cases, each case moves the rate a lot. Widen the tolerance or add cases.
- Forgetting missing categories. A category with no results should fail, not pass silently.
Exercise
Your suite has 50 cases and a baseline pass rate of 0.90. A pull request changes the prompt, and the new pass rate is 0.86. The tolerance is 0.02 and the floor is 0.85. Does the gate pass? Then explain what you would do next, and why a tolerance of 0.02 may be too strict for this suite.
Show answer
The gate fails. The floor check passes because 0.86 is above 0.85, but 0.86 is below 0.90 - 0.02 = 0.88, so the baseline check fails. Next, read the failing cases to see whether the drop is concentrated in one category or in critical cases, and whether it is within run-to-run noise by rerunning the suite several times. With 50 cases, one case moves the rate by 2 points, and the standard error at p = 0.9 is about sqrt(0.9 * 0.1 / 50), roughly 4 points. A 2-point tolerance is smaller than the sampling noise, so it will produce false alarms. Measure the spread over repeated runs of the unchanged prompt and set the tolerance from that, or add more cases.
Exercise
A teammate proposes that CI should overwrite baseline.json with the new pass rate after every successful run on main. Give two reasons this is a bad idea and describe a safer alternative.
Show answer
First, small drops that each stay within tolerance would each become the new baseline, so quality slides down with no one deciding to accept it. Second, a loosened check or an easier dataset could raise the rate and set a baseline that later honest runs cannot meet, or a broken check could lock in a wrong number. A safer approach is to change baseline.json only in a reviewed pull request that explains the reason, keep an absolute floor, and optionally let automation open a pull request that proposes raising the baseline when the rate improves.