Sub topic 7
Baselines and pass thresholds
This chapter assumes you have a golden dataset, deterministic checks that return pass or fail per case, and a way to repeat runs of nondeterministic output. Here you decide what number the suite must reach, and how to fail a build without failing it on noise.
Why a single pass/fail rule does not work
A conventional unit test fails when one assertion fails. An LLM suite with 200 cases will almost never pass all of them. Some cases fail on every run because the model is weak at them. Others flip between pass and fail because sampling varies. If you require 100% passing, the build is red from day one and people learn to ignore it. If you require nothing, a bad prompt edit ships unnoticed.
The fix is to compare against a baseline: the pass rate (or per-case results) recorded for the last version you accepted. A change fails when it is meaningfully worse than that baseline, not when it is imperfect.
Choosing what to store
Store the baseline in the repository, next to the dataset, so it is versioned and reviewed like code.
{
"dataset_version": "2026-11-01",
"model": "example-model-2026-10-15",
"prompt_sha": "a3f9c21",
"runs_per_case": 3,
"pass_rate": 0.91,
"by_tag": {"extraction": 0.95, "adversarial": 0.78}
}Record the model, prompt version, and dataset version with the number. A baseline of 0.91 means little if you cannot tell what produced it.
Keep the per-tag rates too. An overall rate can stay flat while one category collapses and another improves.
Setting a tolerance
The tolerance is the drop you accept before failing. Pick it from measured variance, not by guessing.
- Run the unchanged suite 10 to 20 times on the same model and prompt.
- Record the pass rate of each run.
- Look at the spread. If rates range from 0.89 to 0.93, a drop to 0.90 is noise and a drop to 0.84 is not.
- Set the tolerance slightly wider than the observed spread.
Sample size matters. With 50 cases, one case is 2 percentage points. A 2% tolerance then means a single flipped case can fail the build. With 500 cases, the same tolerance is ten cases.
def pass_rate(results):
return sum(1 for passed in results if passed) / len(results)
def check_regression(current, baseline, tolerance=0.02):
if current < baseline - tolerance:
raise SystemExit(
f"Pass rate {current:.2%} is below baseline {baseline:.2%} "
f"minus tolerance {tolerance:.0%}"
)The function fails only when the rate drops by more than the tolerance. Small improvements and small dips both pass.
Overall gates and per-case gates
An overall rate hides specific damage. Use more than one gate.
| Gate | Catches | Example rule |
|---|---|---|
| Overall pass rate | Broad degradation | Drop of more than 2 points fails |
| Per-tag pass rate | Damage to one category | Any tag drops more than 5 points |
| Critical cases | Safety or format breaks | These must pass in every run |
Mark a small set of cases as critical, for example "never reveals the system prompt" or "always returns valid JSON". These use a hard rule, not a tolerance. Set per-tag tolerances wider than the overall one, because smaller groups are noisier.
Absolute floors
A baseline only says "no worse than before". If the baseline slowly erodes, each change stays inside tolerance while quality sinks. Add an absolute floor, such as 0.85, that fails regardless of the baseline. Ratchet the baseline upward when quality improves, so gains are protected.
Common errors
- Tolerance set by feel. Measure variance first.
- Baseline from a single run. Average several runs, or use the same repeat count in CI as when you recorded it.
- Changing the dataset and the prompt together. The rate moves and you cannot tell why. Change one, rerun, then the other.
- Updating the baseline to make a red build green. Only update it after you have read the failures and decided the new behavior is acceptable.
- Comparing rates across different model versions silently. Store the model name and flag a mismatch.
Exercise
Your suite has 40 cases and a baseline of 0.90. You set a tolerance of 2 percentage points. A harmless prompt edit causes one more case to fail, giving 0.875. Does the build fail, and what would you change?
Show answer
It fails, because 0.875 is below 0.90 minus 0.02 (0.88). One case equals 2.5 points on 40 cases, so the tolerance is smaller than a single case and any flip fails the build. Measure the run-to-run variance, then widen the tolerance to cover it, add cases to reduce the size of each step, or use repeated runs per case so one flaky case counts less.