Lesson 15: Evaluating LLM Systems
Benchmarks, metrics, and LLM-as-judge — how to measure quality, catch regressions, and know when your AI is good enough.
Why Evaluation Matters
"Does it work?" is the hardest question in AI tooling. Without evaluation, you cannot compare models, prompts, or RAG configs — you're guessing. Evaluation turns AI development from vibes into engineering.
The Evaluation Pyramid
| Level | Question | Tools |
|---|---|---|
| Capability | What can this model do? | Public benchmarks |
| Task | Does it do MY task well? | Custom eval sets |
| System | Does the whole pipeline work? | End-to-end evals + metrics |
| Production | Is it good enough to ship? | Human review, monitoring |
Public Benchmarks
| Benchmark | What It Measures |
|---|---|
| MMLU | Knowledge across 57 subjects |
| HumanEval / MBPP | Code generation correctness |
| GSM8K | Grade-school math reasoning |
| GPQA | Graduate-level science reasoning |
| HELM / LMSYS leaderboards | Aggregate comparisons |
Use these to pick a model — but they don't tell you how it performs on your data.
Metrics for Your Own Eval Sets
- Accuracy: % of exact-correct answers (classification, extraction).
- Faithfulness / groundedness: is the answer supported by the source? (RAG)
- ROUGE / BLEU: n-gram overlap with a reference answer (summarization).
- Perplexity: how well the model predicts text (pre-training quality).
- Latency & cost per task: speed and price are quality too.
LLM-as-a-Judge
A strong LLM grades your model's outputs using a rubric. Cheap, fast, scalable — and surprisingly reliable for structured judgments.
SYSTEM: You are an evaluator. Score the ASSISTANT answer 1-5 on:
correctness, completeness, and grounding. Return JSON: {"score": n, "reason": "..."}
USER: QUESTION: ...
REFERENCE: ...
ASSISTANT: ...
Caveats: judges have biases (favor longer, prettier answers; prefer their own style). Calibrate against human scores on a sample before trusting them.
The Eval Loop (Do This Every Change)
- Curate 30–100 real tasks with expected answers (golden set).
- Run the baseline, record scores.
- Change something (prompt, model, chunk size, temperature).
- Re-run the same set, compare scores.
- Ship only if it improves — and keep the set forever (regression tests).
A Starter Eval Checklist
- Golden set of 30+ realistic tasks with expected answers
- Deterministic runs (temperature 0)
- Metrics: accuracy + one quality metric (faithfulness, ROUGE)
- LLM-judge with a rubric, calibrated on ~20 human-scored samples
- Cost + latency tracked per run
- Re-run on every prompt/model change
Key Takeaways
- Benchmarks pick the model; custom evals judge your actual task.
- Build a golden set and re-run it on every change — evaluation is a practice, not a one-time task.
- LLM-as-judge scales review, but calibrate it against humans.
- Track cost and latency alongside quality — a great answer that's too slow is still a bad system.
Next up: Prompt Engineering Track — the anatomy of prompts that get consistent, excellent results.
# Evaluating a model: compare predictions against ground truth
test_set = [
("Capital of France?", "Paris"),
("2 + 2?", "4"),
("Largest planet?", "Jupiter"),
]
predictions = ["Paris", "4", "Mars"] # the model got one wrong
correct = sum(1 for (_, expected), pred in zip(test_set, predictions) if pred == expected)
total = len(test_set)
print(f"Test set size: {total}")
print(f"Correct: {correct}")
print(f"Accuracy: {correct / total * 100:.1f}%")
# A tiny rubric for LLM-as-a-judge
rubric = """
Score 1-5:
- 5: correct, complete, grounded
- 3: partially correct, missing detail
- 1: wrong or hallucinated
"""
print(f"\nJudge rubric:{rubric}")Lesson Code (Python)
# Evaluating a model: compare predictions against ground truth
test_set = [
("Capital of France?", "Paris"),
("2 + 2?", "4"),
("Largest planet?", "Jupiter"),
]
predictions = ["Paris", "4", "Mars"] # the model got one wrong
correct = sum(1 for (_, expected), pred in zip(test_set, predictions) if pred == expected)
total = len(test_set)
print(f"Test set size: {total}")
print(f"Correct: {correct}")
print(f"Accuracy: {correct / total * 100:.1f}%")
# A tiny rubric for LLM-as-a-judge
rubric = """
Score 1-5:
- 5: correct, complete, grounded
- 3: partially correct, missing detail
- 1: wrong or hallucinated
"""
print(f"\nJudge rubric:{rubric}")Console Output
Test set size: 3
Correct: 2
Accuracy: 66.7%
Judge rubric:
Score 1-5:
- 5: correct, complete, grounded
- 3: partially correct, missing detail
- 1: wrong or hallucinated
Code Visualization Tips
- Draw the eval loop as a circle: Golden set → run → score → change → re-run.
- Chart accuracy over successive prompt versions to see the improvement curve.
- Make a scorecard table (accuracy, faithfulness, cost, latency) per model/prompt combo.
Professional Tips & Tricks
- Keep the same golden set across experiments — changing the test is how people fool themselves.
- Score outputs on a 1–5 rubric, not pass/fail — you'll see partial wins.
- Track cost per good answer, not just quality — models differ 10x in price.
Python Code Judge & Practice Arena
LeetCode StyleRun real Python 3.12 WebAssembly code directly in your browser against automated test suites.
Build an Eval Plan
Up next · Continue learning
The Anatomy of an Effective Prompt
Role, context, task, format, constraints — the five building blocks that turn vague requests into precise instructions.