Sub topic 13
Regression tests and evaluation in CI
This chapter assumes you can write Python, call an LLM through an SDK, and read a mean and a confidence interval. It also assumes you have the harness from the earlier chapter and know how a bootstrap interval works.
What a regression test means here
A regression is a drop in quality after you change something. In an LLM application, the change can be a prompt edit, a model version, a retrieval setting, or a code fix. Nothing crashes, so ordinary unit tests stay green while answers get worse.
A regression test runs your evaluation set on every change and compares the result with a stored baseline. The baseline is the score of the version currently in production.
The CI loop
Keep the CI set small and cheap
Every CI run costs model calls and time. Split your data into two tiers.
| Tier | When it runs | Contents |
|---|---|---|
| Smoke set | Every pull request | 30 to 100 cases that cover each known failure mode |
| Full set | Nightly or before release | The whole dataset, plus slower judge-based scoring |
Prefer deterministic checks in the smoke set. They are cheap, and their results do not vary with judge behavior.
Gate on noise, not on a raw difference
Outputs vary between runs. If you fail the build whenever the new score is below the baseline, you will block good changes at random. Instead, fail only when the drop is larger than the sampling noise.
The script below reads two files of per-case scores, one for the baseline and one for the candidate. It bootstraps the paired differences and fails when the whole interval lies below a tolerance.
import json
import random
import sys
def bootstrap_ci(scores, n_resamples=1000, alpha=0.05, seed=0):
rng = random.Random(seed)
n = len(scores)
means = sorted(
sum(rng.choices(scores, k=n)) / n for _ in range(n_resamples)
)
lo = means[int((alpha / 2) * n_resamples)]
hi = means[int((1 - alpha / 2) * n_resamples) - 1]
return lo, hi
def load_scores(path):
with open(path) as f:
return {r["id"]: float(r["passed"]) for r in json.load(f)}
def main(baseline_path, candidate_path, tolerance=0.02):
base = load_scores(baseline_path)
cand = load_scores(candidate_path)
shared = sorted(set(base) & set(cand))
if not shared:
print("No shared case ids; cannot compare.")
return 1
diffs = [cand[i] - base[i] for i in shared]
mean_diff = sum(diffs) / len(diffs)
lo, hi = bootstrap_ci(diffs)
print(f"mean diff {mean_diff:+.3f}, 95% CI [{lo:+.3f}, {hi:+.3f}]")
if hi < -tolerance:
print("FAIL: quality dropped beyond noise.")
return 1
print("OK")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1], sys.argv[2]))The script exits with code 1 on failure, and CI systems treat any nonzero exit code as a failed step. Run it as python gate.py baseline.json candidate.json. Each file holds the results list from the harness, with id and passed fields.
Practical rules
- Pair cases by id. Comparing the same cases removes variation between cases from the difference.
- Pin what you can: model version, temperature, and the dataset version. Record them next to the scores.
- Print the failing case ids in the CI log, so a reader can start error analysis straight away.
- Update the baseline only on the main branch, after a merge. Never update it from a pull request.
- Add a new case whenever a production bug is fixed. The suite then grows from real failures.
Exercise
A pull request lowers the pass rate from 0.90 to 0.88 on 50 cases. The paired bootstrap interval for the difference is [-0.10, +0.05]. Should the gate fail? Why?
Show answer
No. The interval includes zero and positive values, so the drop is within sampling noise. One or two flipped cases explain it. Inspect the failing cases, and rerun on the full set if the change is risky.