Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← Evals and observabilityAI guideIntermediate#evals#ci#testing#promptfoo
Frame · ai-engineering / evals-observability / 07-evals-in-ci-regression-gates.mdGuide 055 / 103

Evals in CI as regression gates

Once you have a dataset and graders, the next step is to run them automatically every time someone changes a prompt, swaps a model or touches retrieval code. That is what turns evals from a research activity into an engineering practice. The goal is the same as with unit tests: catch regressions before merge. The twist is that LLM outputs are noisy and graders cost money, so the gate has to be designed with that in mind.

Why it matters

Prompt changes are code changes, but they rarely get reviewed like code. A one-word edit to a system prompt can shift behaviour across thousands of conversations. If evals only run when someone remembers, they will not run on the change that matters. Putting them in CI means:

  • Every PR gets a before and after comparison.
  • Reviewers see score diffs next to the diff, not just the text change.
  • Model upgrades become a normal PR with evidence, not a leap of faith.

Promptfoo's CI/CD guide lists exactly these goals (catching regressions early and enforcing minimum quality thresholds), and its GitHub Action posts a before and after comparison on the PR. Braintrust, LangSmith and Langfuse all support running experiments from CI and linking results back to the commit.

How it works

The gate is a comparison, not an absolute threshold alone. You want to know both "is it above the floor?" and "did it get worse than main?".

Rendering diagram…

A few design choices make this workable:

Path filters. Only run the expensive suite when prompts, model config, retrieval code or the dataset change. Promptfoo's examples trigger on paths like prompts/** and the config file.

Tiered suites. Run cheap deterministic graders on the full dataset every time. Run LLM judges on a stratified sample on PRs and on the full set nightly.

Baselines. Store the latest main-branch scores as an artifact or in your eval platform. Compare the PR's scores against that, per metric and per failure-mode slice.

Noise budget. Model-graded assertions are non-deterministic. Require a regression to exceed a margin (for example, more than a couple of points on a set large enough to detect that), or to reproduce on a rerun, before failing the build. Anthropic's work on adding error bars to evals is a good guide for sizing that margin honestly.

Pinned models. Pin exact model versions in eval config. Otherwise a provider update can change your scores with no code change at all.

Reference architecture

Rendering diagram…

Code

A promptfoo config for the suite, and a small Python gate that compares results against a stored baseline. Promptfoo assertions like contains, is-json and llm-rubric are part of its documented assertion types.

# promptfooconfig.yaml
prompts:
  - file://prompts/support_answer.txt
providers:
  - id: openai:chat:YOUR_PINNED_MODEL
tests:
  - vars: { question: "How do I reset my password?" }
    assert:
      - type: contains
        value: "Settings"
      - type: llm-rubric
        value: "Gives numbered steps and does not invent menu names."
  - vars: { question: "Return policy for opened items?" }
    assert:
      - type: llm-rubric
        value: "States the 30 day window from the policy and nothing else."
# gate.py: compare per-metric pass rates against main's baseline.
import json
import sys

MARGIN = 0.03   # tolerated drop before failing
FLOOR = 0.85    # absolute minimum pass rate

def load(path: str) -> dict[str, float]:
    return json.load(open(path))

def main(current_path: str, baseline_path: str) -> int:
    current, baseline = load(current_path), load(baseline_path)
    failed = False
    for metric, score in sorted(current.items()):
        base = baseline.get(metric)
        delta = None if base is None else score - base
        status = "ok"
        if score < FLOOR:
            status, failed = "BELOW FLOOR", True
        elif delta is not None and delta < -MARGIN:
            status, failed = "REGRESSION", True
        shown = "new" if delta is None else f"{delta:+.3f}"
        print(f"{metric:30s} {score:.3f} ({shown}) {status}")
    return 1 if failed else 0

if __name__ == "__main__":
    sys.exit(main(sys.argv[1], sys.argv[2]))

You would produce current.json by summarising your eval output into per-metric pass rates (for example, per assertion or per failure-mode tag), and save the same file from main as the baseline.

Trade-offs and pitfalls

  • Flaky gates get ignored. If the check fails randomly, people learn to rerun until green. Size the margin to your noise and rerun automatically once before failing.
  • Aggregate scores hide slice regressions. A one-point overall drop can be a 20-point drop on one critical intent. Gate on important slices, not just the average.
  • Cost creep. A judge call per test row roughly doubles eval cost compared with deterministic checks. Tier the suite and cache outputs for unchanged prompts.
  • Secrets in CI. Eval jobs need provider keys. Scope them, use CI secrets, and avoid running the suite on untrusted forks.
  • Dataset changes masquerading as regressions. When the dataset changes in the same PR, compare against a baseline computed on the new dataset, or split dataset updates into their own PR.
  • Gating on unvalidated judges. Only gate on judges whose agreement with humans you have measured.
  • Unpinned dependencies. Pin eval tool versions as well as model versions; tools change their defaults.

Checklist

  • The eval job runs automatically on PRs that touch prompts, model config, retrieval or datasets.
  • Cheap code graders run on the full set; judges run on a sample per PR and full set nightly.
  • Scores are compared to a stored main-branch baseline per metric and per slice.
  • Failure requires dropping below a floor or exceeding a noise margin.
  • Model versions and eval tool versions are pinned.
  • Results are posted on the PR so reviewers see the diff.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.