Advanced about 6 h
The picture
01
Define success
per task
02
Golden set
real + edge cases
03
Score
exact, schema, judge
04
Compare
with confidence
05
Gate
in CI
Why evals come first
You cannot improve what you cannot measure, and with LLMs your intuition is a poor instrument: outputs read well while being wrong, and a prompt tweak that fixes one case silently breaks five. An eval suite turns "feels better" into evidence, and it is the asset that survives model upgrades.
Build the golden set
- Start from real inputs: logs, tickets, user questions, with sensitive data removed.
- Add edge cases: empty input, very long input, other languages, adversarial phrasing, ambiguous requests, and questions that should be refused or answered "I don't know".
- Add every production failure as a new test the day you fix it.
- Label carefully, ideally by someone who knows the domain, and keep a record of who labelled what.
- Start small (30 to 100 items) and grow. A modest, well-labelled set beats a huge sloppy one.
- Keep a held-out slice you only look at before releases, so you do not overfit your prompts to the suite.
Choose metrics that match the task
- Closed outputs (classification, extraction): exact match, per-field accuracy, precision and recall.
- Structured outputs: schema validity rate plus field accuracy.
- Open text: rubric-based or reference-based judging (next topic), plus hard constraints you can check by code (length, required terms, forbidden terms, citations present).
- Operational: latency, cost, refusal rate, tool-error rate.
A small harness with confidence intervals
import json, random, statistics as st
def run_eval(predict, path="golden.jsonl", score=lambda pred, gold: float(pred == gold["label"])):
rows = [json.loads(l) for l in open(path)]
scores = [score(predict(r["input"]), r) for r in rows]
return rows, scores
def bootstrap_ci(scores, n=2000, alpha=0.05, seed=0):
rnd = random.Random(seed)
means = sorted(st.mean(rnd.choices(scores, k=len(scores))) for _ in range(n))
return means[int(alpha / 2 * n)], means[int((1 - alpha / 2) * n)]
def compare(a, b, n=2000, seed=0):
"""Paired bootstrap on per-item differences: is B better than A?"""
diffs = [y - x for x, y in zip(a, b)]
rnd = random.Random(seed)
means = sorted(st.mean(rnd.choices(diffs, k=len(diffs))) for _ in range(n))
return st.mean(diffs), (means[int(0.025 * n)], means[int(0.975 * n)])
_, base = run_eval(predict_v1)
_, new = run_eval(predict_v2)
delta, (lo, hi) = compare(base, new)
print(f"delta {delta:+.3f} 95% CI [{lo:+.3f}, {hi:+.3f}] ->", "better" if lo > 0 else "worse" if hi < 0 else "no clear difference")
With 50 items, a 4-point gain is usually noise. The interval tells you so.
A declarative runner
# promptfooconfig.yaml
prompts: ["file://prompts/classify_v3.txt"]
providers: ["anthropic:messages:claude-sonnet-5-5"]
tests:
- vars: { ticket: "I don't recognise this charge of 4,999" }
assert:
- type: equals
value: fraud
- vars: { ticket: "What is the capital of France?" }
assert:
- type: equals
value: other
Gate it in CI
# .github/workflows/evals.yml
name: evals
on: [pull_request]
jobs:
evals:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
- run: uv sync
- run: uv run python scripts/run_evals.py --fail-below 0.90 --max-regression 0.02
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
Fail the job if the absolute score drops below a floor or the paired difference against main is significantly negative. Cache model calls where determinism allows, to keep cost and flakiness down. Run the full suite nightly and a fast subset per pull request.
Online evaluation
Offline evals tell you about the past. In production, log inputs, outputs and user feedback (thumbs, edits, retries), sample real traffic for human review, and feed new failures back into the golden set. This loop is how a system gets better after launch.
Common mistakes
- Tuning the prompt against the whole eval set, then reporting its score.
- One aggregate number, no slices by input type.
- Treating model non-determinism as "flaky tests" instead of measuring variance with repeats.
Exercises
- Build a 60-item golden set for a task of yours, including 10 refusals, and report a baseline with a confidence interval.
- Make a deliberate regression in your prompt and show the CI gate catching it.
You are done when you can…
- Build a golden set that includes failures from production, not only easy cases
- Report an accuracy difference with a bootstrap confidence interval
- Block a pull request automatically when an eval regresses