Lesson 16.1 · 1 of 4 · 4 min read · Reviewed 24 Nov 2026
Why evals come before prompts
By the end, you can
- Explain why evals come before prompt work.
- Describe the change, measure, keep loop.
Most teams start an AI feature by writing a prompt and trying it. That works for a demo. It fails as soon as you change anything, because you can’t tell whether the change helped.
What an eval is
test cases (inputs, and expected results or criteria)
|
v
your system (prompt + model + tools)
|
v
grader (code, model or person) --> score --> pass or fail against a bar
The loop
write eval --> run baseline --> change prompt --> rerun --> better? keep : revert
^ |
+---------------- add new failures as test cases <----------+
Why first
- It defines done. Writing test cases forces you to decide what a good answer is.
- It catches regressions. Fixing one case often breaks another. Only a test set shows that.
- It makes model choices cheap. Comparing two models is one more run, not a week of opinion (71.5).
- It speeds you up. Changes that would take a meeting to judge take a minute to score.
An evalEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. doesn’t need to be big to be useful. Ten cases you trust beat no cases at all. Lesson 16.3 builds those ten.
Key points
- An eval is a repeatable test: inputs, a way to score outputs, and a pass bar.
- Without one, every prompt change is a guess judged on two or three examples you happen to try.
- Write a small eval first, then change prompts in a loop: change, measure, keep or revert.
Run a baseline, then measure a change
Build the smallest complete eval (cases, a grader and a pass bar) and use it to decide whether a prompt change stays.
You will have: An eval runner that scores a baseline and a changed system on ten cases and prints keep or revert.
Steps
- Read the ten cases: each has an input question and the refund window a correct answer must state.
- Complete grade so a reply passes only if it contains the expected window and is under 60 words.
- Complete run_eval so it returns the pass rate and the ids of failing cases.
- Run the baseline and the change, and apply the rule: keep only if the score rises and no previously passing case fails.
Done when
- Both systems get a pass rate out of ten cases.
- The change is reverted because it breaks a case that used to pass, even though its score is higher.
- The script prints 'decision: REVERT'.
Open in the Playground No API key needed.
Starter code (Python)
CASES = [
{"id": f"c{i}", "q": q, "window": w} for i, (q, w) in enumerate([
("Can I return shoes?", "30 days"), ("Return a jacket?", "30 days"), ("Return sale items?", "14 days"),
("Return a gift card?", "no returns"), ("Return electronics?", "30 days"), ("Return a mattress?", "100 days"),
("Return opened software?", "no returns"), ("Return socks?", "30 days"), ("Return a sofa?", "100 days"),
("Return a sale jacket?", "14 days")], 1)]
def baseline(case):
# Simulated system: knows the main window, misses the special ones.
return "You can return it within 30 days." if case["window"] != "100 days" else "Please contact us."
def changed(case):
# Simulated prompt change: knows more windows but rambles on furniture.
if case["window"] == "100 days":
return "Large items can be returned within 100 days. " + "We also offer delivery and setup and many other services. " * 6
if "electronics" in case["q"]:
return "Electronics can be returned within 14 days." # the new wording confused a rule
return f"You can return it within {case['window']}." if case["window"] != "no returns" else "Sorry, no returns on this item."
def grade(reply, case):
# TODO: pass if case["window"] appears in reply and the reply has fewer than 60 words.
return True
def run_eval(system):
# TODO: return (pass_rate, failing_ids)
return 1.0, []
PASS_BAR = 0.8
b_rate, b_fail = run_eval(baseline)
c_rate, c_fail = run_eval(changed)
print(f"baseline: {b_rate:.0%} failing {b_fail}")
print(f"changed: {c_rate:.0%} failing {c_fail}")
newly_broken = sorted(set(c_fail) - set(b_fail))
keep = c_rate > b_rate and not newly_broken
print("newly broken:", newly_broken)
print("decision:", "KEEP" if keep else "REVERT", "| meets bar:", c_rate >= PASS_BAR)
Show a solution
CASES = [
{"id": f"c{i}", "q": q, "window": w} for i, (q, w) in enumerate([
("Can I return shoes?", "30 days"), ("Return a jacket?", "30 days"), ("Return sale items?", "14 days"),
("Return a gift card?", "no returns"), ("Return electronics?", "30 days"), ("Return a mattress?", "100 days"),
("Return opened software?", "no returns"), ("Return socks?", "30 days"), ("Return a sofa?", "100 days"),
("Return a sale jacket?", "14 days")], 1)]
def baseline(case):
# Simulated system: knows the main window, misses the special ones.
return "You can return it within 30 days." if case["window"] != "100 days" else "Please contact us."
def changed(case):
# Simulated prompt change: knows more windows but rambles on furniture.
if case["window"] == "100 days":
return "Large items can be returned within 100 days. " + "We also offer delivery and setup and many other services. " * 6
if "electronics" in case["q"]:
return "Electronics can be returned within 14 days." # the new wording confused a rule
return f"You can return it within {case['window']}." if case["window"] != "no returns" else "Sorry, no returns on this item."
def grade(reply, case):
return case["window"] in reply and len(reply.split()) < 60
def run_eval(system):
failing = [c["id"] for c in CASES if not grade(system(c), c)]
return 1 - len(failing) / len(CASES), failing
PASS_BAR = 0.8
b_rate, b_fail = run_eval(baseline)
c_rate, c_fail = run_eval(changed)
print(f"baseline: {b_rate:.0%} failing {b_fail}")
print(f"changed: {c_rate:.0%} failing {c_fail}")
newly_broken = sorted(set(c_fail) - set(b_fail))
keep = c_rate > b_rate and not newly_broken
print("newly broken:", newly_broken)
print("decision:", "KEEP" if keep else "REVERT", "| meets bar:", c_rate >= PASS_BAR)