Sub topic 3
Measure first: an evaluation set and a baseline
Every adaptation approach in this tutorial (prompting, RAG, fine-tuning) changes the system's behavior. Without a measurement, you cannot tell whether a change helped, hurt, or only felt better on the three examples you tried. This chapter covers how to build a small evaluation set and record a baseline before you change anything.
This chapter assumes you can call a chat-style LLM API, read Python, and know roughly what a context window is. It does not cover how to build a retrieval pipeline or how to fine-tune. Those come later.
Why measure before you adapt
Teams often start with the solution. Someone sees a bad answer, concludes "we need RAG" or "we need fine-tuning," and spends weeks building it. Then nobody can say whether the system improved. Three problems follow from skipping measurement:
- You cannot diagnose. The previous chapter separated knowledge gaps from behavior gaps. You can only sort failures into those groups if you have a collection of failures to look at.
- You cannot compare. The decision framework later in this tutorial asks "does the prompt baseline pass?" That question has no answer without a baseline and a pass bar.
- You cannot detect regressions. A prompt tweak that fixes one case often breaks another. Only a fixed set run repeatedly will show it.
An evaluation set (eval set) is a fixed collection of inputs, each with a definition of a good output. A baseline is the score of the simplest reasonable system on that set, recorded before you try improvements. Every later change is judged against it.
The measure-first loop
The loop is the same for all three approaches. Only the "change one thing" step differs.
Building the eval set
Where cases come from
Good cases come from real use, in this order of preference:
- Production or pilot logs. Real user inputs show the phrasing, typos, and edge cases you would not invent.
- Known failures. Every bug report that says "the model got this wrong" becomes a case.
- Domain expert writing. Ask someone who knows the task to write inputs and the correct outputs. This is slower but covers gaps in the logs.
- Synthetic cases. You can have a model generate candidate inputs. A human must review them and write or confirm the expected outputs. Model-written expected outputs would otherwise inherit the model's mistakes.
How many
Start with 30 to 100 cases. That is small enough to review by hand and large enough to show big differences. A set of 20 cases is too noisy: one case is 5 percentage points. If you need to detect a 2-point improvement, you need hundreds of cases. Begin small and grow the set as you find new failures.
What to cover
A set made only of typical inputs will look good and hide problems. Include:
- Typical cases, weighted roughly as they occur in real traffic.
- Edge cases: empty input, very long input, mixed languages, ambiguous wording.
- Cases that need facts the model may not have, such as internal policy or recent changes. These later reveal knowledge gaps.
- Cases with a required style or format, such as a JSON schema or house tone. These later reveal behavior gaps.
- Cases where the right answer is "I don't know" or "out of scope." Without them, you will reward systems that guess.
Tag each case with its category. Tags let you report scores per group, which is what makes the diagnosis step possible.
Keep a held-out portion
If you tune your prompt against all your cases, you will overfit: the prompt will fit those exact cases and perform worse on new ones. Split the set. Use the development set (about 70 percent) while iterating, and keep a held-out set (about 30 percent) that you run only occasionally to confirm that gains are real. If you later fine-tune, the training data must never include held-out cases.
Choosing a grader
A grader is the code or person that decides whether an output passes. Pick the cheapest grader that is reliable for your task.
| Grader | Good for | Weakness |
|---|---|---|
| Exact match | Classification labels, extraction of IDs | Fails on harmless wording differences |
| Programmatic check | JSON validity, schema, required fields, length limits, regex | Cannot judge meaning |
| Reference comparison | Answers with a known key fact ("contains 30 days") | Misses wrong text around the key fact |
| Model as judge | Tone, helpfulness, faithfulness to context | Has its own biases; must be checked against human labels |
| Human review | Final calibration, ambiguous cases | Slow and costly |
If you use a model as judge, first have a person grade 20 to 30 outputs and check how often the judge agrees. If agreement is low, the judge scores are not measuring what you care about.
Running a baseline
The baseline should be the simplest honest attempt: a short, clear instruction and no examples, no retrieval, no tuning. Starting simple matters because it tells you how far prompting alone gets you. If the baseline already meets your bar, you are finished and avoid unneeded complexity.
The harness below runs any function that maps an input to an output. It uses a stand-in function so the code runs without an API key. In practice, replace baseline_model with a call to your model.
import json
from collections import defaultdict
EVAL_SET = [
{"id": 1, "tag": "billing", "input": "I was charged twice this month.", "expected": "billing"},
{"id": 2, "tag": "billing", "input": "My invoice shows the wrong amount.", "expected": "billing"},
{"id": 3, "tag": "bug", "input": "The export button crashes the app.", "expected": "bug"},
{"id": 4, "tag": "bug", "input": "Search returns an error page.", "expected": "bug"},
{"id": 5, "tag": "other", "input": "Do you have a dark mode?", "expected": "other"},
{"id": 6, "tag": "edge", "input": "", "expected": "other"},
]
def baseline_model(text):
# Stand-in for a real model call. Replace with your API call.
lowered = text.lower()
if "charged" in lowered or "invoice" in lowered:
return "billing"
if "crash" in lowered:
return "bug"
return "other"
def exact_match(output, expected):
return output.strip().lower() == expected.strip().lower()
def run_eval(model_fn, cases, grader):
results = []
for case in cases:
output = model_fn(case["input"])
results.append({
"id": case["id"],
"tag": case["tag"],
"output": output,
"passed": grader(output, case["expected"]),
})
return results
def summarize(results):
by_tag = defaultdict(lambda: [0, 0])
for r in results:
by_tag[r["tag"]][1] += 1
by_tag[r["tag"]][0] += int(r["passed"])
total_passed = sum(p for p, _ in by_tag.values())
total = sum(n for _, n in by_tag.values())
return {
"overall": total_passed / total,
"by_tag": {tag: p / n for tag, (p, n) in by_tag.items()},
}
results = run_eval(baseline_model, EVAL_SET, exact_match)
summary = summarize(results)
print(json.dumps(summary, indent=2))
for r in results:
if not r["passed"]:
print("FAILED:", r["id"], r["tag"], repr(r["output"]))
with open("baseline.json", "w") as f:
json.dump({"summary": summary, "results": results}, f, indent=2)Running this prints an overall score and a score per tag. In this toy example, case 4 ("Search returns an error page.") fails because the stand-in only looks for the word "crash." A failure like that is the starting point of the diagnosis: ask whether the model lacked a fact or behaved wrongly.
The last lines save the baseline to a file. Commit it next to the eval set and the prompt. When you change something, run the same harness and compare the new summary to baseline.json.
Reading the baseline
Do not stop at the overall score. Read the failures themselves, because the categories of failure tell you which lever to pull.
- Failures concentrated in cases that need internal or recent facts suggest a knowledge gap, which points toward RAG.
- Failures on format, tone, or label conventions despite clear instructions suggest a behavior gap. Try better prompts and examples first. If they still fail, fine-tuning becomes a candidate.
- Failures that vary from run to run on the same input suggest sampling noise. Lower the temperature, or run each case several times and report the pass rate.
- Failures where the expected answer is wrong or ambiguous are eval set bugs. Fix the case. This happens often in the first pass.
Also define the pass bar now, before you see results from improved systems. A bar such as "at least 90 percent overall and no tag below 80 percent" prevents you from moving the goalposts after the fact.
Common errors
- Changing several things at once. If you edit the prompt, add examples, and change the temperature together, you cannot tell which change mattered.
- Leaking eval cases into prompts. Using eval cases as few-shot examples inflates the score. Draw examples from a separate pool.
- Averaging away problems. An overall 92 percent can hide a 40 percent score on a rare but important tag. Always report per tag.
- Treating small differences as real. On 50 cases, a one-case change is 2 points. Do not conclude anything until the difference is larger than the noise you see when re-running the same system.
- Never refreshing the set. Users change what they ask. Add new production failures to the set regularly.
Summary
Build a tagged eval set from real inputs, include edge cases and "I don't know" cases, and hold part of it back. Pick the cheapest reliable grader. Run the simplest system, record the score per tag, and define a pass bar. The failures you read in this step drive every decision that follows.
Exercise
Your eval set has 40 cases and your baseline scores 85 percent overall. After you rewrite the prompt, the score is 87.5 percent. Should you conclude the new prompt is better? What would you do next?
Show answer
Not yet. A 2.5-point change on 40 cases is one case, which is within normal noise. Re-run each system several times to see how much the score varies, check the per-tag scores and which specific cases changed, and compare on the held-out set. Add more cases, especially from real failures, so smaller differences become detectable, and accept the new prompt only if the gain exceeds the run-to-run noise and no tag got worse.
Exercise
You are building an eval set for a support assistant that must answer from an internal refund policy. Name three kinds of cases besides typical questions that you should include, and say what each helps you find.
Show answer
(1) Questions that depend on specific policy details or recent changes, which reveal knowledge gaps that RAG could address. (2) Cases with a required output format or tone, which reveal behavior gaps that prompting or fine-tuning could address. (3) Questions the policy does not cover, where the right answer is "I don't know" or "out of scope," which reveal whether the system guesses or invents facts. Edge cases such as empty or very long input are also valid.