Learning path: LLM Evals: Test an AI Feature Before and After You Ship · Step 1 of 3
Why You Cannot Ship an LLM Feature Without an Eval: Five Parts, Three Graders, One Tiny Eval
A friendlier prompt looked better on three questions and broke on others. An eval catches that: a fixed set of cases, a grader, a pass rate and a threshold. A tiny Python eval scores two prompt versions on the same six questions: v1 passes 83% and ships, v2 passes 50% and is blocked.
What you will learn
- Define an eval as a repeatable test set plus scoring, run on every change
- Name the five parts: dataset, system under test, graders, score and threshold
- Choose between rule checks, an LLM judge and human review
- Run a tiny eval in Python that ships one prompt and blocks another
Before you start
- Basic Python
- What an LLM Can and Cannot Do
An eval is a repeatable test set plus scoring, run on every change. Think of it as unit tests, but for the behaviour of a language model. This article shows why you need one, what's inside it, and a tiny eval in plain Python that you can run in a second.
A prompt change that looked better
A support bot answers customer questions. Someone says the answers sound cold, so the prompt goes from version 1 to version 2: Be warm and friendly. To check it, we try three questions. All three answers look nicer. Great, we ship it.
In production, other questions break. The warm answers forgot the facts: refund time, free-shipping limit, opening hours. Three examples that look good tell you nothing about the rest. We need a way to check all of them, every single time.
A driving test, not a feeling
A driving test has a fixed route and a checklist. The examiner doesn't say "I felt good about this driver". Most of us check a prompt the other way: try a few examples, it feels better, ship it. Different examples each time, no number, and nobody can repeat it.
An eval works like the driving test: a fixed set of cases, every case scored, a pass rate compared with a threshold, then ship or block. Same cases each time, one number, and anyone can repeat it.
The five parts of an eval
- Dataset: the test cases. Each has a question and what a good answer must contain. (Building one properly is the topic of Building a Golden Dataset.)
- System under test: the bot, with its prompt, answering each question.
- Graders: decide if each answer passes.
- Score: how many cases passed, as a pass rate.
- Threshold: below it, the change doesn't ship.
Three kinds of graders
| Grader | How it works | Good for | Watch out |
|---|---|---|---|
| Rule check | Code looks at the answer: does it contain the fact? Is it short enough? | Cheap, instant, same result every time | Only checks what you can write as a rule |
| LLM as judge | Another model scores the answer against a short rubric | Tone and meaning | The judge can be wrong too; check it against human marks |
| Human review | A person reads a sample and marks it | The final word on quality | Slow and costly; use it on a small sample |
Start with rule checks. Add a judge and humans only where a rule can't decide.
tiny_eval.py
Here's a tiny eval with no model call and no keys. The answers for each prompt version were written by hand and saved, so the result is easy to follow. The cases first:
"""A tiny eval: saved support-bot answers, a rule grader, a pass rate. No LLM, no keys."""
CASES = [
{"question": "How do I reset my password?", "must_include": "forgot password",
"v1": "Use the reset option on the page.",
"v2": "Click Forgot password on the sign-in page and we will email you a link."},
{"question": "How do I cancel my plan?", "must_include": "billing",
"v1": "Open Settings, then Billing, then Cancel plan.",
"v2": "Happy to help! Head to Settings and choose Billing to cancel."},
{"question": "How fast is my data deleted?", "must_include": "30 days",
"v1": "Your data is deleted within 30 days.",
"v2": "Your data is deleted within 30 days of your request."},
{"question": "How long do refunds take?", "must_include": "5 business days",
"v1": "Refunds arrive within 5 business days.",
"v2": "Great question! Refunds are quick and easy."},
{"question": "When is shipping free?", "must_include": "$50",
"v1": "Shipping is free on orders over $50.",
"v2": "Shipping is free on big orders."},
{"question": "When is support open?", "must_include": "9 am",
"v1": "Support is open from 9 am, Monday to Friday.",
"v2": "We are always here for you, any time!"},
]
THRESHOLD = 0.8
Each case has a question, the fact a good answer must include, and the saved answer from each prompt version. THRESHOLD = 0.8 means 80% of the cases must pass. Then the grader and the score:
def grade(answer, must_include):
return must_include.lower() in answer.lower()
def run_eval(version):
results = [grade(case[version], case["must_include"]) for case in CASES]
rate = sum(results) / len(CASES)
print(f"prompt {version}: {sum(results)}/{len(CASES)} passed ({rate:.0%})")
for case, ok in zip(CASES, results):
if not ok:
print(f" FAIL {case['question']} (needs '{case['must_include']}')")
print(" ->", "SHIP" if rate >= THRESHOLD else "BLOCK")
if __name__ == "__main__":
run_eval("v1")
run_eval("v2")
grade is a rule check: is the required fact inside the answer? Both sides are lowercased, so capitals don't matter. run_eval grades every case, prints the pass rate and each failure with the missing fact, then compares the rate with the threshold.
Same cases, two prompts
python tiny_eval.py
prompt v1: 5/6 passed (83%)
FAIL How do I reset my password? (needs 'forgot password')
-> SHIP
prompt v2: 3/6 passed (50%)
FAIL How long do refunds take? (needs '5 business days')
FAIL When is shipping free? (needs '$50')
FAIL When is support open? (needs '9 am')
-> BLOCK
Prompt v1 passed 5 of 6, 83%, above 80%: ship. Its one failure is the password question, because the answer never said "forgot password". Prompt v2 passed 3 of 6, 50%: block. It lost the refund time, the free-shipping limit and the opening hours.
Remember, v2 looked friendlier on the first three questions. The eval shows it lost the facts on the other three. A vibe check would have shipped it.
Where evals run
An eval only protects you if it runs without anyone having to remember:
- Before merge: every prompt or code change runs the eval first, and a low score blocks the merge. That's set up in Regression Testing in CI.
- Nightly: a bigger test set runs on a schedule, so slow drift gets caught early.
- On production samples: score a small sample of real traffic, and add the failures to the test set.
That last one matters most: every bug you find in production becomes a new test case, so the eval gets stronger over time.
Common mistakes
- Checking a new prompt on the three examples that made you write it.
- Changing the test cases between runs. Then two scores can't be compared.
- Grading for one exact sentence. Check the facts a good answer needs; many wordings can pass.
- Using an LLM judge for things a rule can check, like "contains $50". Slower, costlier, and less reliable.
- Having a score but no threshold. Without a pass mark, nothing blocks.
Quick recap
| Idea | In one line |
|---|---|
| Eval | A repeatable test set plus scoring, run on every change |
| Five parts | Dataset, system under test, graders, score, threshold |
| Graders | Rules first; a judge or humans only where rules can't decide |
| This run | v1 83%, ship; v2 50%, block |
| Where | Before merge, nightly, on production samples |
Try it yourself
- Run the file and read the SHIP and BLOCK lines.
- Add a seventh case with its own required fact, and an answer for each version.
- Move
THRESHOLDto 0.5 and then 0.9. Which version still ships?
Related course on Udemy
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)Related posts
Building a Golden Dataset for LLM Evals: Cases, a Schema, a Coverage Table and a Seeded Split
The answer key for a support bot: 24 cases in one JSONL file, from 12 past tickets, 8 edge cases and 4 attacks. A Pydantic schema catches 4 problems in a broken file, a stats table finds that payments and account have no hard case, and a seeded split gives the same 16 dev and 8 test cases every time.
Retrieval Evals: Score the Retriever With Recall@K, MRR and nDCG Before Blaming the Model
When a RAG answer is wrong, check the retriever first. Score two retrievers on 24 graded queries with Recall@5, MRR and nDCG@5: overall there's no clear winner (0.757 vs 0.819, 0.854 vs 0.826, 0.769 vs 0.782), but the paraphrase slice drops to about 0.5 for both, and one query scores zero everywhere.
Regression Testing an LLM Bot in CI: A Golden Set, Two pytest Gates and GitHub Actions
A teammate changes one prompt line to make answers shorter, and four of ten golden questions lose their facts. A pytest eval on saved answers catches it: 12 passed for the old prompt, 2 failed gates and 4 xfailed cases for the new one, exit code 1, and the pull request check turns red.
Testing a RAG Bot Before It Ships: Slices, a Release Gate per Slice, and the Week After
In a simulated 210-case eval, a new model lifts the average from 0.895 to 0.929 and leaks 4 restricted documents. A gate per slice blocks it where the average says release. Plus why 20 of 20 can mean 0.88, and why the gate must also run when the index changes.