Courses / GenAI & LLM / Module 8
Module 8: Evaluation and testing: golden sets, LLM-as-judge, evals in CI
12 h · theory 4 · hands-on 5 · project 2 · revision 1
You will be able to
- Build a golden set and measure field-level accuracy
- Use LLM-as-judge with calibration against human labels
- Run evals in CI and block regressions
- Track quality, latency and cost together
Capstone increment: Eval suite (DeepEval + pytest) on the extraction golden set that runs on every pull request and posts scores.
Job-description skills: LLM evaluation, Testing · Lab tools: deepeval, promptfoo, pytest
1. Evals are tests for behaviour you can’t assert exactly
Unit tests check code paths with exact assertions. LLM output varies, so you also need evaluations: a fixed set of inputs (the golden set), scorers that judge each output, and a comparison against the last accepted version. Evals are how you know a prompt, model or retrieval change helped rather than just felt better.
Start from error analysis, not from metrics. Read 50-100 real outputs, write down what went wrong in your own words, group the failures, and only then decide what to measure. Generic metrics chosen up front usually measure the wrong thing.
2. Build the golden set
Collect real inputs (anonymised), including the hard and ugly ones: scans, missing fields, adversarial questions. Label the expected output for each, ideally by two people with disagreements resolved. 50 good cases beat 1,000 easy ones.
Keep it alive. Every production failure becomes a new case. Version the golden set like code, and never tune prompts on the same cases you report scores on: keep a held-out portion.
3. Cheap scorers first
Most checks need no model: schema validity, exact or normalised field match, regex and range checks, “cites only sources that exist”, length limits, latency and cost. They are fast, free and deterministic. Normalise before comparing (₹48,260 equals 48260.00) or you'll measure formatting instead of correctness.
Use an LLM as a judge only for qualities code can't check: is the answer faithful to the sources, does it address the question, is the tone right. Give the judge a specific rubric, examples of pass and fail, and ask for a pass/fail with a reason rather than a vague 1-10 score.
4. Calibrate the judge
An LLM judge is itself a model that can be wrong. Before trusting it, label 50-100 outputs by hand and measure agreement with Cohen's kappa, which corrects for agreement by chance. Iterate on the rubric until kappa is high, then spot-check regularly.
Try it below: a vague rubric agrees with humans barely better than chance, while a specific rubric with examples becomes a usable instrument.
| Human: pass | Human: fail | |
|---|---|---|
| Judge: pass | 8 | 6 bad answers passed |
| Judge: fail | 3 good answers failed | 3 |
Agreement 55% · Cohen’s κ 0.06 · catches 33% of the failures (κ corrects for agreement by chance: below 0.4 is weak, above 0.7 is good)
- #1 Correct refund steps, cites policy · human pass · judge 9/10 → pass
- #2 Confident, but invents a 60-day window · human fail · judge 8/10 → pass ✗
- #3 Correct, a little long · human pass · judge 7/10 → pass
- #4 Answers a different question · human fail · judge 7/10 → pass ✗
- #5 Correct, terse · human pass · judge 6/10 → fail ✗
- #6 Correct with the right form · human pass · judge 9/10 → pass
- #7 Polite, fluent, wrong amount · human fail · judge 9/10 → pass ✗
- #8 Correct, asks a useful follow-up · human pass · judge 8/10 → pass
- #9 Refuses a valid request · human fail · judge 5/10 → fail
- #10 Correct, says when it can’t know · human pass · judge 7/10 → pass
- #11 Leaks another customer’s order id · human fail · judge 8/10 → pass ✗
- #12 Correct · human pass · judge 9/10 → pass
- #13 Correct but clumsy wording · human pass · judge 5/10 → fail ✗
- #14 Missing the deadline the user asked for · human fail · judge 6/10 → fail
- #15 Correct, cites two sources · human pass · judge 8/10 → pass
- #16 Right answer, wrong currency · human fail · judge 9/10 → pass ✗
- #17 Correct, informal tone · human pass · judge 6/10 → fail ✗
- #18 Empty answer after a tool error · human fail · judge 4/10 → fail
- #19 Correct · human pass · judge 8/10 → pass
- #20 Hallucinated tracking link · human fail · judge 7/10 → pass ✗
Guided experiments
- With rubric v1, try every pass mark from 5 to 9. What is the best κ you can get? Which kinds of bad answer does v1 keep passing?
- Switch to rubric v2. Find the pass mark with the best κ. What changed in the rubric that made the judge useful?
- Agreement can look fine while κ is low. Set v1 with pass mark 1 (everything passes). What is the agreement, and why is κ zero?
- You have budget to label 50 more answers by hand. Which answers would you pick to label, and why?
5. Evals in CI
Run the eval suite on every pull request that touches prompts, models, retrieval or parsing. Compare with the baseline from main, allow a small tolerance for noise, and block the merge on a real regression. Post the scores as a PR comment so reviewers see them.
Track quality, latency and cost together. A change that gains one point of accuracy but doubles cost is a product decision, not an automatic win. DeepEval and promptfoo both integrate with pytest or CI to do this.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 8.1: Error analysis
Run the capstone on 60 documents, read every output, and write a free-text note for each failure. Group the notes into 4-6 failure categories with counts.
Expected: A failure taxonomy with counts and one example each; the top two categories become your first eval metrics.
Lab 8.2: Eval suite in CI (capstone increment)
Build the extraction golden set (at least 50 documents), add DeepEval or pytest scorers for field accuracy and faithfulness, and a GitHub Actions job that runs on pull requests, compares with main and comments the scores.
Expected: A pull request that worsens a prompt is blocked by CI with a comment showing which metric regressed.
Lab 8.3: Calibrate an LLM judge
Hand-label 60 RAG answers for faithfulness. Write two judge rubrics, measure Cohen’s kappa for each, and keep the better one.
Expected: Kappa for both rubrics and the final rubric committed to the repo with its measured agreement.
Go deeper
Videos
- LLM Evals: Common Mistakes · Hamel Husain · ~28 min. The mistakes most teams make with evals, from someone who has fixed them at many companies.
- Intro To Error Analysis: Creating Custom Data Annotation Apps · Hamel Husain · ~41 min. How to read and label outputs efficiently, the step most teams skip.
- Getting Evals Right for LLM Applications | Interrupt 26 · LangChain · ~17 min. A short conference talk on building evals that track real failures.
Further reading
- Article Your AI Product Needs Evals · Hamel Husain. A practitioner's case for building evals first, with the levels of testing that work in production.
- Paper Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena · Zheng et al., NeurIPS 2023. Measures how often LLM judges agree with people, and documents position and verbosity bias.
- Article Evaluating the Effectiveness of LLM-Evaluators (aka LLM-as-Judge) · Eugene Yan. A practical review of what judges are good and bad at, with the papers behind each finding.
GitHub repositories
- confident-ai/deepeval: The pytest integration and the G-Eval and faithfulness metrics; how test cases and thresholds are written.
- promptfoo/promptfoo: The GitHub Action example that runs evals on pull requests and posts results.
- vibrantlabsai/ragas: How faithfulness is computed by breaking answers into claims and checking each against the context.
Checkpoint quiz
Interview questions
- How would you evaluate a document-extraction system before launch?
- How do you know whether your LLM judge can be trusted?
- Design an evaluation pipeline that runs in CI. What blocks a merge?
- Your eval scores went up but users are complaining more. What happened?
- How do you balance quality, latency and cost when comparing two models?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).