Skip to content
Visual explainer 2h to learn 3 steps

Regression evals in CI

Block prompt or model changes that lower eval scores.

By Invicly Tech, , in AI Engineering with Python. About 12 minutes to read.

Topic 26 of 33

In short

Regression evals run your eval suite automatically on every prompt, model or code change. If scores drop below a threshold, the build fails before the change reaches users.

Explained simply

Prompts and model settings are code. Changing one word in a prompt, or switching to a newer model, can quietly break answers that worked yesterday. Regression evals run your eval set automatically on every such change, just like unit tests run on every code change.

A CI job (continuous integration, the robot that checks every pull request) runs your app on the eval cases, scores the outputs and compares the scores with a threshold. If the score is too low, the job fails and the change cannot be merged until someone looks.

LLM outputs vary a little from run to run, so scores wobble even when nothing changed. Thresholds therefore need a small margin, and you need enough cases to tell a real drop from noise.

Evals cost money and time. Run a small, fast set on every pull request that touches prompts or model code, and the full set every night or before a release.

Press Play on a diagram to walk through it one step at a time.

SequenceEvals gate a pull request
Developer
CI job
Eval runner
LLM API
  1. 1Push prompt change
    Developer to CI job: Push prompt change
  2. 2Run eval suite
    CI job to Eval runner: Run eval suite
  3. 3Generate outputs for cases
    Eval runner to LLM API: Generate outputs for cases
  4. 4Outputs
    LLM API to Eval runner: Outputs
  5. 5Scores vs thresholds
    Eval runner to CI job: Scores vs thresholds
  6. 6Pass, or fail with diff
    CI job to Developer: Pass, or fail with diff
LayersTest tiers for an LLM app
  1. 1
    Unit tests

    No model calls, every commit

  2. 2
    Smoke evals

    20 to 50 cases, every relevant PR

  3. 3
    Full eval suite

    Hundreds of cases, nightly

  4. 4
    Human review

    Sampled outputs before a release

In depth

What should trigger an eval run

Run evals when anything that affects model behaviour changes: prompt files, model names and parameters, retrieval settings such as chunk size or k, tool definitions, the eval data itself, and the app code around them. Path filters in your CI config let you skip expensive evals for pull requests that only touch the README or the CSS.

Also run on a schedule. Hosted models can change behind the same name: some providers offer aliases that move to newer versions over time. A nightly run catches drift you did not cause. Where your provider offers dated or pinned model versions, use them in production so changes happen only when you choose, through a pull request that runs the evals.

Record, with every run, the git commit, the model version, the prompt version and the dataset version. A score without that context cannot be reproduced.

Noise: why scores wobble and what to do

Even with temperature 0, many hosted models are not perfectly deterministic, and LLM judges add their own variation. So the same commit can score 86% on one run and 83% on the next.

The number of cases sets how much wobble to expect. The standard error of a pass rate is roughly the square root of p times (1 minus p) divided by n. For a pass rate of 0.85 on 50 cases, that is about 0.05, or 5 points. A 3-point drop on 50 cases is therefore not strong evidence of a regression. On 400 cases the standard error falls below 2 points.

You have four tools. Use more cases. Repeat runs and average them. Compare per case against the baseline (paired), which is more sensitive than comparing two averages. And set thresholds with a margin rather than exactly at today's score.

  • Standard error is about sqrt(p(1-p)/n)
  • p 0.85, n 50: about 5 points of wobble
  • Paired per-case comparison beats comparing averages
  • Low temperature reduces, but rarely removes, variation

Thresholds, baselines and must-pass cases

A good gate combines three rules. An absolute floor taken from your success criteria: correctness must never drop below 80%. A relative check against the baseline, the scores of the current main branch: the pull request may not be more than 3 points worse. And must-pass cases: a small tagged group, such as safety refusals or legally sensitive answers, that must pass every time, because one failure there is unacceptable no matter the average.

Keep thresholds per metric. A blended score lets a gain in tone hide a loss in correctness. Store the baseline as a JSON file of per-case results, updated automatically when main changes, so every pull request compares against a known reference.

When a change is a deliberate trade-off, such as a slight drop in one metric for a big cost saving, update the threshold explicitly in the same pull request, so the decision is reviewed and recorded.

CompareThree gate rules
Absolute floor
  • From success criteria
  • e.g. correctness at least 80%
  • Never goes below, ever
Relative to baseline
  • Compared with main
  • e.g. no more than 3 points worse
  • Catches gradual decay
Must-pass cases
  • Small tagged set
  • Safety and legal cases
  • One failure fails the build

Reporting: show what got worse

A red X with accuracy 0.81 < 0.85 tells the developer almost nothing. A useful report shows each metric next to its baseline and threshold, then lists the cases that flipped from pass to fail, with the input, the old output and the new output. Cases that flipped from fail to pass are worth listing too, because they show what improved.

In GitHub Actions you can append Markdown to the file named in the GITHUB_STEP_SUMMARY environment variable, and it appears on the job's summary page. Many teams also post a short comment on the pull request. Save the full outputs as a build artifact so reviewers can read every answer, not just the failing ones.

Reviewers then judge the change like any code review: is this a real regression, an acceptable trade-off, or a case whose label needs fixing?

Keeping CI evals fast and affordable

Split the suite into tiers. A smoke set of 20 to 50 tagged cases runs on every relevant pull request in a few minutes. The full set runs nightly and before releases. Run cases concurrently, with a semaphore to stay under the provider's rate limits.

Cache model outputs keyed by a hash of the model, the prompt version and the input. If a pull request only changes one prompt, cases using other prompts reuse cached outputs instead of paying again. Never let the cache hide a real change, so include everything that affects the output in the key.

Store the API key as a CI secret and give CI its own key with a spend limit. Note that in GitHub Actions, workflows triggered by pull requests from forks do not receive repository secrets by default, which protects your key but means evals for outside contributors need a maintainer-triggered run.

Learn it in 3 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Run evals in a CI job~40m
  2. 2
    Set score thresholds~40m
  3. 3
    Fail builds on regressions~40m

Key points

  • Treat prompt and model changes like code changes: gated by tests.
  • Set thresholds slightly below the current baseline to tolerate noise.
  • Report per-case diffs so reviewers see what got worse.
  • Use a small fast suite on every PR and a full suite nightly.

Key terms

Tap a card to flip it. 0/4 known

Examples

python
# test_evals.py, run with: pytest -q
import json
from my_app import answer
from my_evals import score

THRESHOLD = 0.85

def test_faq_accuracy():
    cases = [json.loads(line) for line in open('evals/faq.jsonl')]
    results = [score(answer(c['input']), c['expected']) for c in cases]
    accuracy = sum(results) / len(results)
    assert accuracy >= THRESHOLD, f'accuracy {accuracy:.2f} < {THRESHOLD}'

A pytest gate that fails the build below the threshold.

A GitHub Actions workflow for evals

Step 1: trigger on pull requests that touch prompts, app code or eval data, using a paths filter. Step 2: also run every night at 03:00 UTC to catch provider-side drift. Step 3: check out the code, set up Python and install dependencies. Step 4: run the eval tests with pytest, passing the API key from repository secrets as an environment variable. If any assert fails, pytest exits non-zero and the check goes red on the pull request.

yaml
name: evals
on:
  pull_request:
    paths: ["prompts/**", "app/**", "evals/**"]
  schedule: [{ cron: "0 3 * * *" }]
jobs:
  evals:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with: { python-version: "3.12" }
      - run: pip install -r requirements.txt
      - run: pytest -q tests/evals
        env: { LLM_API_KEY: "${{ secrets.LLM_API_KEY }}" }

Comparing against a baseline, case by case

The eval run writes results.json as a map from case ID to pass or fail. main's last run is stored as baseline.json. Step 1: find cases that passed on the baseline and fail now; these are the regressions to show reviewers. Step 2: compute both pass rates. Step 3: fail the job if the score is below the absolute floor of 0.80 or more than 3 points under the baseline. Step 4: print everything, so the job log explains the verdict.

python
import json, sys

base = json.load(open("evals/baseline.json"))  # {"case-id": true, ...}
new = json.load(open("evals/results.json"))
regressed = [cid for cid, ok in base.items() if ok and not new.get(cid, False)]
score = sum(new.values()) / len(new)
base_score = sum(base.values()) / len(base)
print(f"score {score:.1%} (baseline {base_score:.1%})")
for cid in regressed:
    print("REGRESSED:", cid)
if score < 0.80 or score < base_score - 0.03:
    sys.exit(1)

Quick reference

  • Trigger evals on changes to prompts, model settings, retrieval config, tools and eval data
  • Run nightly too: hosted model aliases can change behaviour without a commit
  • Wobble on a pass rate is about sqrt(p(1-p)/n): about 5 points for p 0.85 and n 50
  • Gate with an absolute floor, a margin below baseline, and must-pass cases
  • Report per-case regressions with input, old output and new output
  • GitHub Actions: append Markdown to $GITHUB_STEP_SUMMARY for a readable report
  • Cache outputs keyed by model, prompt version and input to save cost
  • Give CI its own API key with a spend limit; fork PRs do not get secrets by default

Common mistakes

  • Setting thresholds so tight that random variation fails builds.
  • Running the full expensive suite on every commit.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Your main branch scores 86% on 50 cases. A PR scores 84%. What is the best reading?

Question 2

2Why run evals on a nightly schedule even when nobody pushed code?

Question 3

3Which tagged cases should fail the build after a single failure?

Question 4

4What should the eval cache key include?

Question 5

5An outside contributor opens a PR from a fork, and the eval job fails with a missing API key. Why?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Write a pytest test that loads must-pass cases (tag must_pass) from a JSONL file and asserts each one passes, so a single failure fails the build with the case ID in the message.

  2. Exercise 2medium

    Write a function that returns the standard error of a pass rate and use it to decide if a drop from baseline is bigger than two standard errors.

  3. Exercise 3hard

    Write a script that appends a Markdown table of metric, baseline, new score and status to the GitHub job summary, using the GITHUB_STEP_SUMMARY environment variable.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

How do I test LLM prompts in CI?
Treat the eval set as a test suite: run the app on each case in a CI job, score the outputs, and fail the job when scores fall below set thresholds.
Should I set temperature to 0 for evals?
Use the same settings as production so you test what users get. If production uses a higher temperature, run cases more than once and average.
How do I stop evals from making CI too expensive?
Run a small smoke set on relevant pull requests, the full set nightly, cache outputs that did not change, and give CI a key with a spend limit.
What if a prompt change is better overall but fails a few old cases?
Review those cases. If the trade-off is acceptable, update the baseline or thresholds in the same pull request so the decision is visible and recorded.
ShareXLinkedInWhatsApp