Evals in CI/CD & release gates
Run the eval suite automatically on every prompt, model, retrieval or tool change, and block the merge or release when scores fall below floors or regress versus the baseline beyond noise.
Analogy: Unit tests for behavior: nobody merges code that breaks the build, so nobody should merge a prompt that breaks the refund answers.
How it works
- Pin everything that shapes behavior, like a dated model snapshot instead of a moving alias; scores need fixed configs.
- Tier by cost: a fast ~50–200-case subset on every PR, the full suite with judges nightly and pre-release.
- Check regressions per slice, not just the average: a flat average can hide a broken slice.
- Report in the PR: score deltas, newly failing cases, and cost and latency per case.
- Tools matter less than discipline: a failing eval blocks the merge, and every production bug becomes a new case.
Check yourself
Answer to mark it learned; your answers aren't scored.
The nightly suite drops 4 points on Spanish queries. No prompt, code or data change was merged since the last green run, and the drop reproduces on rerun. What's the most likely cause?
Go deeper
Full explanation
Eval CI runs your eval suite automatically whenever something that shapes behavior changes: prompt, model or model version, retrieval (chunking, embeddings, index), tool definitions, decoding parameters. It turns evals from a one-off report into a release gate, like unit tests for code.
How it works:
- Pin and version everything that defines behavior: prompt templates, the model snapshot (
gpt-4o-2024-08-06, not the movinggpt-4oalias), index build, tool schemas. A score only means something against a pinned config. - Tier the suite by cost. On every PR, a fast subset (~50–200 cases, deterministic graders first, a cheap judge) in minutes. Nightly and pre-release, the full suite with LLM judges and several trials per case.
- Gate on floors and on the baseline. Absolute floors (zero critical safety failures, near-100% schema validity) plus no regression beyond noise versus
main, per slice, not just on the average. See Non-determinism: pass@k & variance for sizing that noise band. - Report in the PR: score deltas, newly failing cases, cost and latency per case.
Tools: promptfoo (YAML config + CLI, runs in any CI), Braintrust and LangSmith (hosted datasets, experiments, side-by-side diffs), OpenAI Evals, or plain pytest with your graders. The tool matters less than the discipline: a failing eval blocks the merge, and every production bug becomes a new case.
Code promptfoo PR gate wired into GitHub Actions
# promptfooconfig.yaml: PR gate (fast subset; nightly runs the full suite)
prompts:
- file://prompts/support_v7.txt # prompt versioned in git
providers:
- id: openai:gpt-4.1-mini-2025-04-14 # any model; pin the dated snapshot, never an alias
config: { temperature: 0 }
defaultTest:
assert:
- type: latency
threshold: 4000 # ms per case
- type: cost
threshold: 0.003 # USD per case
tests:
- vars: { question: "Can I get a refund after 45 days?" }
assert:
- type: llm-rubric # judge, graded against the policy
value: States the 30-day refund limit and offers escalation; invents no exception
- vars: { question: "Export my last invoice as JSON" }
assert:
- type: is-json # deterministic grader first
# ...~150 more cases, tagged by slice (refunds, billing, es-419...)
# .github/workflows/evals.yml (excerpt)
on:
pull_request:
paths: ["prompts/**", "evals/**", "retrieval/**", "tools/**", "models.yaml"]
jobs:
evals:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci # promptfoo version pinned in package-lock.json
- run: npx promptfoo eval -c promptfooconfig.yaml --no-cache -o results.json || true # gate.py decides
env: { OPENAI_API_KEY: "${{ secrets.OPENAI_API_KEY }}" }
- run: python scripts/gate.py results.json --baseline main --max-drop 0.05 --per-sliceReal example
A team edits the system prompt to make answers shorter. The PR job runs 180 cases in ~6 minutes for ~$1.50. The average is flat (0.86 → 0.85, inside noise), but the refunds slice drops from 0.92 to 0.71: the shorter prompt lost the escalation clause. The per-slice gate blocks the merge, and the PR comment lists the 9 newly failing cases. Separately, the nightly suite (2,400 cases × 3 trials, ~$90) catches a 4-point drop on Spanish queries with no code change at all: the embedding model was referenced by a moving alias. Pinning it becomes a rule.
Trade-offs +3 · −3
+ You gain
- Catches regressions at the PR, where they cost minutes instead of incidents.
- Turns prompt and model changes into reviewable diffs with evidence, not vibes.
- Pinned configs make every score reproducible and comparable across months.
− You pay
- Real money and time per run; LLM judges usually dominate the bill.
- Noisy scores cause flaky gates unless thresholds respect run-to-run variance.
- A green gate is only as good as the suite: stale cases give false confidence.
Use it when
As soon as more than one person edits prompts or more than one config runs in production. Start with 30–50 cases and deterministic graders; add a case for every bug.
Avoid it when
Throwaway prototypes in their first days, before you know what "good" looks like: do error analysis by hand first, then encode what you learn.
Numbers to know 3
- Rule of thumb: PR subset of ~50–200 cases in under ~10 minutes; full suite nightly and before each release.
- Noise floor: at n=200 and an 85% pass rate, one run's 95% CI is ±~5 pts. Set regression thresholds above it or add trials.
- Dated snapshots (e.g., gpt-4o-2024-08-06) stay fixed; aliases like gpt-4o get repointed to newer snapshots over time.
Common pitfalls 4
- Gating only on the average: one slice can collapse while the mean stays flat.
- Unpinned model aliases or index rebuilds: the baseline moves without any code change.
- Thresholds tighter than run-to-run noise: the gate flakes and people learn to rerun until green.
- Triggering only on prompt files, so retrieval, tool-schema and model-config changes skip the gate.
Interview questions 2
Answer out loud first, then reveal.
How would you set up evals in CI for an LLM product?Show answer
I treat every behavior-defining artifact as code: prompts, model snapshot, retrieval config and tool schemas are versioned, and any change triggers evals. On PRs, a fast subset of ~150 cases with deterministic graders and a cheap judge, under ten minutes; nightly and before release, the full suite with several trials. Gates are absolute floors for safety and format plus no regression versus main's baseline beyond noise, per slice. Results post into the PR with newly failing cases, cost and latency. And every production incident becomes a test case.
Your eval gate is flaky: the same commit passes and fails. What do you do?Show answer
First I measure the noise: run the same commit five to ten times and look at the spread per case. Flaky cases usually mean an ambiguous expected answer or a judge rubric that's too loose, so I fix or remove those. Then I make the gate statistical: compare against the baseline with a paired test on the same cases, use multiple trials for the stochastic slices, and set the regression threshold above the measured noise. What I won't do is let people rerun until green; that trains everyone to ignore the gate.