Slides · Evaluation and model adaptation

Evaluating LLM systems

Evaluating LLM systems

How do you know the new version is better, and that it did not break something else? Layers, a validated judge, and a decision you can defend.

Concept

“It looks better” is not evidence

  • Every change to a prompt, model, retriever or tool can fix one kind of input and quietly break another.
  • Outputs are open-ended and vary between runs, so one assertion is not enough. Evaluation becomes a small system: datasets, graders, metrics, thresholds and a feedback loop from production.
  • Hamel Husain’s essay describes three levels of evaluation (assertions, model and human review, A/B tests) whose cost rises with each level, and says he often runs the first level on every code change because assertions are quick and inexpensive enough to run that often.
  • Without this, regressions are found through user complaints.

Source1 Your AI Product Needs Evals

Diagram

The evaluation pyramid

Diagram: Five layers are stacked like a pyramid, drawn from the bottom up.

Deterministic checks: schema, tests, regex

Reference metrics: exact match, F1

LLM judge: rubric or pairwise

Human review: calibration and hard cases

Online signals: A/B, edits, retries

Diagram summary: Five layers are stacked like a pyramid, drawn from the bottom up. Cheap deterministic checks form the base, then reference metrics, a model judge and human review, with online signals at the top, the slowest and most trusted. Run many cheap checks often and few costly ones rarely.

Anthropic’s agent-evals article gives the same split for graders: code-based graders are fast, cheap and reproducible but can reject a valid answer that is worded differently than expected; model-based graders are flexible but need calibration against humans; human graders are the gold standard but slow and expensive.

Source2 Demystifying evals for AI agents

Process

Start with error analysis, then choose metrics

Diagram: Read real failures first, sort and count them, and choose metrics that measure the biggest categories.

Sample failing traces

Sort into failure categories

Tally by category

Choose metrics for the top categories

Build the eval

Check the next sample of failures

Diagram summary: Read real failures first, sort and count them, and choose metrics that measure the biggest categories. Repeat on fresh failures so the eval keeps tracking what breaks.
  • The lesson’s rule of thumb is 50 to 100 traces to start. Husain’s essay stresses removing friction from looking at data and never stopping.
  • Metrics picked first tend to measure what is easy, so the score rises while users still complain.

Source1 Your AI Product Needs Evals

Compare

What each layer catches

LayerCatchesCostBlind spot
Deterministic checksSchema, tool arguments, forbidden content, unit tests for codeNear zeroCannot judge quality
Reference metricsExact or F1 match where a gold answer existsLowWord overlap (ROUGE, BLEU) is weak for open text (course judgment)
LLM judgeHelpfulness, tone, faithfulness at scaleModel callsIts own biases and drift
Human reviewHard cases, subjective quality, safety, judge calibrationHighestSlow, small samples
Online signalsReal use: edits, retries, abandonment, escalationsFree but delayedNoisy, arrive after release

Push every check you can down the pyramid: a check that code can do should not be paid for in judge calls.

Source2 Demystifying evals for AI agents

Code

Cheap checks first, judge only if they pass

Python

def layered(case, output, checks, judge_fn):
    for name, fn in checks:
        if not fn(output):
            return {"verdict": "fail", "layer": name, "judge_called": False}
    return {"verdict": judge_fn(case, output), "layer": "judge", "judge_called": True}

Tests run on this code with two cheap checks (valid JSON, has a citation):

TestResult
Output that is not JSON fails at the first check, judge not calledpass
Valid JSON without a citation fails at the second check, judge not calledpass
Output passing both is sent to the judge exactly oncepass

Illustrative cost: 400 cases at $0.01 per judge call is $4.00 if every case is judged. If 30 percent fail a deterministic check, only 280 reach the judge: 280×$0.01=$2.80280 \times \$0.01 = \$2.80.

Check yourself

Check: a SQL-writing assistant

Match each check to a layer: (i) the generated query parses, (ii) running it on a test database returns the same rows as a reference query, (iii) the explanation is easy for an analyst to follow, (iv) analysts keep the query without editing it.

Answer

(i) deterministic check. (ii) a reference-based check, run by code against gold results. (iii) an LLM judge with a rubric, calibrated by human review. (iv) an online signal (keep or edit rate), which arrives after release and is noisy.

Concept

A judge scales, so measure how far to trust it

Zheng et al. (NeurIPS 2023 Datasets and Benchmarks) tested strong LLMs as judges on MT-bench and Chatbot Arena.

  • On MT-bench first-turn questions, GPT-4 as pairwise judge agreed with human votes 85 percent of the time when ties were excluded, against 81 percent between two humans. With ties counted the figures were 66 and 63 percent.
  • These are results for those models and benchmarks in 2023, not a guarantee for your judge, rubric or data.
  • So before relying on a judge, measure its agreement with humans on your own labelled sample.

Source3 Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena

Compare

Known judge biases and mitigations

BiasWhat the paper reportsMitigation
PositionMost judges favoured the first answer; GPT-4 was consistent in 65.0 percent of cases, Claude-v1 in 23.8 percentJudge both orders, count a win only if both agree
VerbosityIn a “repetitive list” attack on 23 answers, the failure rate was 8.7 percent for GPT-4 and 91.3 percent for Claude-v1 and GPT-3.5Rubric that penalises padding; check length against score
Self-enhancementGPT-4 gave itself a 10 percent higher win rate, Claude-v1 25 percent; the authors say the data cannot settle whether the bias existsUse a judge from a different model family
Limited reasoningOn 10 math questions GPT-4 failed 14 of 20 judgments by default and 3 of 20 with a reference answerGive a reference answer where one exists

Course guidance, not from the paper: also use a clear anchored rubric, structured output, and repeated judging or a majority vote for important decisions, since temperature 0 alone does not make a judge deterministic.

Source3 Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena

Code

Swapping the order, in code

Python

def swapped_verdict(judge, question, a, b):
    v1 = judge(question, a, b)      # "first" or "second"
    v2 = judge(question, b, a)
    if v1 == "first" and v2 == "second": return "A"
    if v1 == "second" and v2 == "first": return "B"
    return "tie"                    # verdict flipped with the order

Tests run on toy judges:

TestResult
A judge that always says “first”: every pair becomes a tiepass
A judge that prefers the longer answer keeps the same winner in both orderspass
A judge forced to say “first” 30 percent of the time, 2,000 pairs: about 1,400 A, 0 B and about 600 ties (exact counts depend on the seed)pass

The paper’s mitigation is the same idea: count a win only if the answer wins in both orders, and treat inconsistent verdicts as ties. It removes slot preference, not other biases.

Source3 Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena

Diagram

The validation loop

Diagram: Humans and the judge label the same sample and their agreement is measured beyond chance.

yes

no

Sample of outputs

Human labels

Judge labels

Compare: kappa and label balance

Agreement good enough
for this decision?

Use the judge, re-check periodically

Fix rubric or judge, relabel

Diagram summary: Humans and the judge label the same sample and their agreement is measured beyond chance. If it is good enough for the decision at hand the judge is used with periodic re-checks; if not, the rubric or judge is fixed and the sample relabelled.

Math

Cohen’s kappa: agreement beyond chance

κ=po−pe1−pe\kappa = \frac{p_o - p_e}{1 - p_e}
SymbolMeaning
pop_oObserved agreement: share of items with the same label
pep_eAgreement expected if both labellers assigned labels at random with their own label frequencies
κ\kappa1 is complete agreement, 0 is no agreement beyond chance, the minimum value means complete disagreement

scikit-learn’s documentation defines kappa this way and gives no qualitative scale, so choose the bar by the cost of a wrong decision.

Source4 cohen_kappa_score

Worked example

Worked example: from a confusion table

200 outputs labelled by a human and by the judge (illustrative).

CountJudge passJudge failRow total
Human pass11822140
Human fail105060
Column total12872200
  • po=118+50200=0.84p_o = \dfrac{118 + 50}{200} = 0.84.
  • Human pass rate 140200=0.70\dfrac{140}{200} = 0.70, judge pass rate 128200=0.64\dfrac{128}{200} = 0.64.
  • pe=0.70×0.64+0.30×0.36=0.448+0.108=0.556p_e = 0.70 \times 0.64 + 0.30 \times 0.36 = 0.448 + 0.108 = 0.556.
  • κ=0.84−0.5561−0.556=0.2840.444≈0.64\kappa = \dfrac{0.84 - 0.556}{1 - 0.556} = \dfrac{0.284}{0.444} \approx 0.64.

Read the table too: the judge catches 50 of 60 true failures (83 percent) and wrongly fails 22 of 140 good outputs. Report kappa together with the label balance and the error pattern.

Source4 cohen_kappa_score

Check yourself

Check: which way does the judge err?

On 100 outputs: both pass 30, human pass and judge fail 10, human fail and judge pass 20, both fail 40.

  1. Compute kappa.
  2. Is the judge too strict or too lenient?
Answer
  1. po=70100=0.70p_o = \dfrac{70}{100} = 0.70. Human pass rate 0.40, judge pass rate 0.50, so pe=0.40×0.50+0.60×0.50=0.50p_e = 0.40 \times 0.50 + 0.60 \times 0.50 = 0.50. κ=0.70−0.500.50=0.40\kappa = \dfrac{0.70 - 0.50}{0.50} = 0.40.
  2. Too lenient: it passes 20 outputs that humans failed and fails only 10 that humans passed. For a release gate that matters more than the single number.

Diagram

Datasets: dev set to iterate, held-out set to gate

Diagram: The dataset is split into a dev set you tune against and a held-out set used only to decide a release.

Versioned dataset

Dev set: iterate freely

Held-out set: only gates releases

Tune prompts, retriever, model

Candidate change

Release gate

Diagram summary: The dataset is split into a dev set you tune against and a held-out set used only to decide a release. Tuning against the held-out set makes it a second dev set, and the gate stops meaning anything.
  • Draw cases from production logs and experts; include edge cases, unanswerable questions, several languages, long inputs and cases where refusing is right.
  • Record why an answer is right. Version the dataset. Hand-check synthetic cases, which skew easy.

Worked example

Worked example: why the gate set must be touched once

A simulation (illustrative) of this effect: twenty prompt variants all have the same true pass rate of 0.80. Each is scored on the same 100-case set, and you keep the best.

MeasurementAverage result over 2,000 simulated runs
Best of 20 on the set you tuned against0.872
The chosen variant on a fresh set0.799

The best score looks like a 7-point gain, yet nothing improved: picking the winner selected luck. Keep a held-out set that is not used for choosing, so its score still predicts new traffic.

Math

A test set is a sample

SE=p(1−p)n\mathrm{SE} = \sqrt{\frac{p(1 - p)}{n}}half-width≈1.96×SE(approximate 95 percent interval)\text{half-width} \approx 1.96 \times \mathrm{SE} \qquad \text{(approximate 95 percent interval)}
SymbolMeaning
ppPass rate
nnNumber of cases
SE\mathrm{SE}Standard error of the measured pass rate

For p = 0.8 (illustrative):

Cases nHalf-width
4003.9 points
1007.8 points
6010.1 points
2515.7 points

This is why slices need care: a slice of 25 cases has an interval of about plus or minus 16 points.

Code

Paired bootstrap on the same cases

Python

import random

def paired_bootstrap(a, b, resamples=10_000, seed=11):
    rng = random.Random(seed)
    diffs = [y - x for x, y in zip(a, b)]       # B - A per case
    n = len(diffs)
    means = sorted(sum(rng.choice(diffs) for _ in range(n)) / n
                   for _ in range(resamples))
    return sum(diffs) / n, means[int(.025*resamples)], means[int(.975*resamples) - 1]

Illustrative data: 60 cases, A passes 42, B passes 47. Both pass 40, only A 2, only B 7, neither 11.

ResultValue
Difference B - A+8.3 points
Paired 95% interval-1.7 to +18.3 points
Unpaired interval (cases resampled separately)-6.7 to +23.3 points

Interval includes zero, so the gain is not shown. Resampling the case differences keeps each case’s difficulty paired, which is what SciPy’s paired=True option does for its bootstrap. Tests run on this code: identical variants give an exact zero interval, a clear improvement gives an interval above zero, and the same seed repeats the result.

Source5 scipy.stats.bootstrap

Diagram

From scores to a ship decision

Diagram: A real improvement needs an interval that excludes zero, then acceptable slices, safety, latency and cost.

no

yes

no

yes

Same cases, per-case differences

Bootstrap interval

Interval excludes zero?

Not shown: add cases or call it neutral

Slices, safety,
latency, cost ok?

Do not ship as is

Shadow, canary, watch online signals

Diagram summary: A real improvement needs an interval that excludes zero, then acceptable slices, safety, latency and cost. Only then does the change move to staged rollout.

Check yourself

Check: how many cases?

You expect a pass rate near 0.8 and want a single score accurate to about plus or minus 3 points (95 percent). Roughly how many cases do you need?

Answer

n=1.962×0.8×0.20.032=3.8416×0.160.0009≈683n = \dfrac{1.96^2 \times 0.8 \times 0.2}{0.03^2} = \dfrac{3.8416 \times 0.16}{0.0009} \approx 683 cases. Comparing two variants on the same cases needs a separate paired calculation.

Compare

Benchmarks shortlist; product evals decide

WeaknessWhat it meansEvidence
ContaminationTest items leaked into training dataMagar and Schwartz (ACL 2022) note that web-scale training data may overlap downstream test sets. In their experiments models exploited the contaminated data in some cases, and in others memorised it without exploiting it
SaturationTop models cluster near the ceiling, so differences vanishThe Dynabench authors argue models quickly reach outstanding benchmark scores yet fail simple challenge examples; Anthropic observes that once an eval is saturated it can still catch regressions but no longer shows improvement
Domain mismatchTasks, language, format or risk differ from yoursThe Dynabench authors say models also struggle in real-world use, which is the gap between benchmark tasks and yours (the course’s reading)

Use a benchmark to choose what to try and your product eval to choose what ships. When they disagree, check your eval’s sample and labels first, then trust it.

Sources6 Data Contamination: From Memorization to Exploitation7 Dynabench: Rethinking Benchmarking in NLP2 Demystifying evals for AI agents

Check yourself

Check: a Hindi support bot

You shortlisted two models from an English multiple-choice leaderboard. Your product answers Hindi support chats. Which weakness is most relevant, and what do you add?

Answer

Domain mismatch (language, format and task). Add a product eval from logged or expert-written Hindi support cases, sliced by intent and language, with a judge validated against Hindi-speaking reviewers.

Process

Answering “how do you know it is good?”

Provenance: common industry pattern; no company-specific claim.

  1. Read failures and name the categories.
  2. Layer the checks: code first, judge for the rest, humans for hard cases and calibration.
  3. Validate the judge against humans with kappa and swap orders.
  4. Compare on the same cases with an interval, and slice.
  5. Gate on a held-out set, use benchmarks only to shortlist.
  6. Roll out in stages and feed production failures back into the dev set.

Summary

Recap

  • Pyramid: deterministic, reference, judge, human, online. Push checks down.
  • Error analysis first, then datasets, then gates.
  • Judges are biased: validate with kappa, swap orders, use a rubric.
  • Dev set to iterate, held-out set to gate; slice the metrics and respect the noise.
  • Benchmarks shortlist, product evals decide.

References

References & Sources (1 of 2)

  1. Your AI Product Needs Evals (opens in a new tab)

    Hamel Husain2024Article

    Used for Three levels of evaluation with rising cost, assertions cheap enough to run on every change, and the habit of looking at data.

  2. Demystifying evals for AI agents (opens in a new tab)

    Mikaela Grace, Jeremy Hadfield, Rodrigo Olivares, Jiri De Jonghe2026Article

    Used for Code-based, model-based and human graders with their strengths and weaknesses, calibrating model graders against humans, and eval saturation.

  3. Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (opens in a new tab)

    Lianmin Zheng, Wei-Lin Chiang, Ying Sheng, Siyuan Zhuang, et al.2023NeurIPS 2023 Datasets and Benchmarks TrackPaper

    Used for GPT-4 judge agreement with humans on MT-bench (85 percent without ties against 81 percent between humans), position, verbosity and self-enhancement bias figures, math failure rates, and the swap-order mitigation.

  4. cohen_kappa_score (opens in a new tab)

    scikit-learn2026Documentation

    Used for The definition and range of Cohen's kappa as (p_o - p_e) / (1 - p_e).

  5. scipy.stats.bootstrap (opens in a new tab)

    SciPy2026Documentation

    Used for Bootstrap confidence intervals by resampling, and the paired option that keeps pairing intact.

References

References & Sources (2 of 2)

  1. Data Contamination: From Memorization to Exploitation (opens in a new tab)

    Inbal Magar, Roy Schwartz2022ACL 2022 (60th Annual Meeting of the Association for Computational Linguistics), Volume 2: Short PapersPaper

    Used for Web-scale training data may overlap downstream test sets, and models can memorise contaminated data.

  2. Dynabench: Rethinking Benchmarking in NLP (opens in a new tab)

    Douwe Kiela, Max Bartolo, Yixin Nie, Divyansh Kaushik, et al.2021NAACL 2021 (North American Chapter of the Association for Computational Linguistics: Human Language Technologies)Paper

    Used for Models quickly reach outstanding benchmark performance yet fail simple challenge examples and struggle in real-world use.