Skip to content

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.

Golden setinputs + expectedRun systemprompt / model vNCode checksexact, schema, regexLLM judgecalibrated rubricComparevs main baselineCI gatepass or blockOn every pull requestnew failure in production → add it to the golden set
Evals are tests for behaviour you can’t assert exactly. Cheap code checks first, a judge only where needed.
Common misconception: “We’ll use a public benchmark.” Benchmarks measure general ability. Your users’ documents, questions and failure modes are specific; only your own golden set tells you whether your system works.

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.

Calibrate an LLM judge against human labels20 answers, each labelled pass or fail by a person. The judge scores 1–10; you choose its rubric and pass mark.
Human: passHuman: fail
Judge: pass86 bad answers passed
Judge: fail3 good answers failed3

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. #1 Correct refund steps, cites policy · human pass · judge 9/10 → pass
  2. #2 Confident, but invents a 60-day window · human fail · judge 8/10 → pass ✗
  3. #3 Correct, a little long · human pass · judge 7/10 → pass
  4. #4 Answers a different question · human fail · judge 7/10 → pass ✗
  5. #5 Correct, terse · human pass · judge 6/10 → fail ✗
  6. #6 Correct with the right form · human pass · judge 9/10 → pass
  7. #7 Polite, fluent, wrong amount · human fail · judge 9/10 → pass ✗
  8. #8 Correct, asks a useful follow-up · human pass · judge 8/10 → pass
  9. #9 Refuses a valid request · human fail · judge 5/10 → fail
  10. #10 Correct, says when it can’t know · human pass · judge 7/10 → pass
  11. #11 Leaks another customer’s order id · human fail · judge 8/10 → pass ✗
  12. #12 Correct · human pass · judge 9/10 → pass
  13. #13 Correct but clumsy wording · human pass · judge 5/10 → fail ✗
  14. #14 Missing the deadline the user asked for · human fail · judge 6/10 → fail
  15. #15 Correct, cites two sources · human pass · judge 8/10 → pass
  16. #16 Right answer, wrong currency · human fail · judge 9/10 → pass ✗
  17. #17 Correct, informal tone · human pass · judge 6/10 → fail ✗
  18. #18 Empty answer after a tool error · human fail · judge 4/10 → fail
  19. #19 Correct · human pass · judge 8/10 → pass
  20. #20 Hallucinated tracking link · human fail · judge 7/10 → pass ✗
Guided experiments
  1. 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?
  2. Switch to rubric v2. Find the pass mark with the best κ. What changed in the rubric that made the judge useful?
  3. Agreement can look fine while κ is low. Set v1 with pass mark 1 (everything passes). What is the agreement, and why is κ zero?
  4. You have budget to label 50 more answers by hand. Which answers would you pick to label, and why?
In production: Judges have biases: they prefer longer answers, answers in their own style, and the first of two options. Randomise order in pairwise comparisons and keep answers length-matched where you can.

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 code

Labs

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

Further reading

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

1. What should come before choosing eval metrics?
2. A judge agrees with humans 85% of the time, but κ is 0.1. Why?
3. Which check needs an LLM judge rather than code?
4. Why allow a small tolerance in the CI gate?
5. A production failure is reported. What should happen to the golden set?

Interview questions

  1. How would you evaluate a document-extraction system before launch?
  2. How do you know whether your LLM judge can be trusted?
  3. Design an evaluation pipeline that runs in CI. What blocks a merge?
  4. Your eval scores went up but users are complaining more. What happened?
  5. 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).