Skip to content
AgenticAIWiki
  1. Learn
  2. Part 2
  3. 15. Prompt chaining and multi-pass review
  4. 15.3

Lesson 15.3 · 3 of 5 · 5 min read · Reviewed 24 Nov 2026

Eval-driven prompt iteration

By the end, you can

  • Improve prompts by measuring them on a test set.
  • Change one thing at a time and compare scores.

“It looks better” is how prompts get worse. A change that fixes one case can quietly break three others.

The loop

  1. Build a test set: 30 to 100 real inputs with expected outputs or grading criteria, including hard cases.
  2. Score the current prompt.
  3. Change one thing.
  4. Re-score and compare. Keep the change only if the score improves without new failures.
  5. Add failures you find in production to the test set.

How to grade

  • Exact or code checks for structured fields.
  • A model graderLLM-as-judge: Using a language model with a rubric to grade another model’s outputs. with a rubricRubric: A written set of criteria and score levels that a grader applies to each output. for open-ended output.
  • Human review of a sample, especially early on.

Part 3 covers each of these in depth.

Why one thing at a time

If you change the role, the examples and the format together and the score drops, you won’t know why. Small steps make the cause obvious.

Key points

  • Prompt changes that look better on one example often make others worse.
  • Keep a test set of real inputs with expected outputs, and score every prompt version on it.
  • Change one thing at a time, compare scores, and add new failures to the set.
Hands-on labRuns in the Playground

Score prompt versions on a test set

Compare prompt versions on a whole test set, list what each change fixed and broke, and keep only clear improvements.

You will have: A comparison report for three simulated prompt versions against a 12-case test set, with a keep or revert decision for each.

Steps

  1. Read the 12 test cases and three simulated prompt versions (functions standing in for model calls).
  2. Complete score so it returns the set of case ids that pass for a version.
  3. Complete compare so it lists fixed and broken cases relative to the baseline.
  4. Apply the rule: keep a version only if it fixes at least one case and breaks none.

Done when

  • v2 is reverted because it breaks cases, even though it fixes some.
  • v3 is kept: it fixes cases and breaks none.
  • The script prints 'v2: REVERT' and 'v3: KEEP'.

Open in the Playground No API key needed.

Starter code (Python)
CASES = [{"id": i, "words": w, "needs_ref": r} for i, (w, r) in enumerate(
    [(40, True), (90, False), (130, True), (60, False), (200, True), (30, False),
     (110, True), (75, False), (150, False), (50, True), (95, True), (180, False)], 1)]

def passes(case, max_words, cites):
    return case["words"] <= max_words and (cites or not case["needs_ref"])

VERSIONS = {
    "v1": lambda c: passes(c, 120, cites=c["id"] % 3 != 0),      # baseline
    "v2": lambda c: passes(c, 160, cites=c["id"] % 2 == 0),      # three changes at once
    "v3": lambda c: passes(c, 160, cites=c["id"] % 3 != 0),      # one change: length rule
}

def score(version):
    # TODO: return the set of case ids where VERSIONS[version](case) is True.
    return set()

def compare(base, new):
    # TODO: return (fixed, broken) as sorted lists: fixed = in new not base; broken = in base not new.
    return [], []

base = score("v1")
print(f"v1 baseline: {len(base)}/{len(CASES)}")
for v in ["v2", "v3"]:
    s = score(v)
    fixed, broken = compare(base, s)
    verdict = "KEEP" if fixed and not broken else "REVERT"
    print(f"{v}: {len(s)}/{len(CASES)} fixed {fixed} broken {broken} -> {v}: {verdict}")
Show a solution
CASES = [{"id": i, "words": w, "needs_ref": r} for i, (w, r) in enumerate(
    [(40, True), (90, False), (130, True), (60, False), (200, True), (30, False),
     (110, True), (75, False), (150, False), (50, True), (95, True), (180, False)], 1)]

def passes(case, max_words, cites):
    return case["words"] <= max_words and (cites or not case["needs_ref"])

VERSIONS = {
    "v1": lambda c: passes(c, 120, cites=c["id"] % 3 != 0),      # baseline
    "v2": lambda c: passes(c, 160, cites=c["id"] % 2 == 0),      # three changes at once
    "v3": lambda c: passes(c, 160, cites=c["id"] % 3 != 0),      # one change: length rule
}

def score(version):
    return {c["id"] for c in CASES if VERSIONS[version](c)}

def compare(base, new):
    return sorted(new - base), sorted(base - new)

base = score("v1")
print(f"v1 baseline: {len(base)}/{len(CASES)}")
for v in ["v2", "v3"]:
    s = score(v)
    fixed, broken = compare(base, s)
    verdict = "KEEP" if fixed and not broken else "REVERT"
    print(f"{v}: {len(s)}/{len(CASES)} fixed {fixed} broken {broken} -> {v}: {verdict}")
Quick checkYou tweak a prompt and the one example you tried looks better. What should you do before shipping?
How sure are you?
Pick an answer and how sure you are