Sub topic 1
Why an LLM App Needs Its Own Evaluation Dataset
Prerequisites
This chapter assumes you can read basic Python and JSON/JSONL (one JSON object per line). It also assumes you have called an LLM API or built a small app on one, and that you know what a prompt and a model output are. You should be comfortable with a mean, a proportion, and the idea of sample size. No evaluation experience is needed.
What an evaluation dataset is
An evaluation dataset is a fixed collection of test cases for your app. Each case holds an input the app might receive, plus whatever you need to decide whether the app's output is acceptable. That is usually a reference answer or a rubric (a list of criteria). You run the app on every case, grade each output, and aggregate the grades into scores.
The dataset is not training data. You never update model weights with it. Its job is to give you a repeatable measurement, so that "the app works" becomes a number you can compare across versions.
A single case can be as small as one line of JSONL:
{"id": "refund-001", "input": "Can I return a laptop after 45 days?", "reference": "No. Returns are accepted within 30 days of delivery.", "tags": ["returns", "policy"], "source": "production_log", "difficulty": "easy"}Later chapters explain each field. For now, notice that the case has a stable id, an input, a reference, tags for slicing results, and provenance (where the case came from).
Why public benchmarks are not enough
Public benchmarks measure general model ability on tasks someone else chose. They answer "which model is generally stronger?" They do not answer "does my support bot quote the right return policy?" Several gaps explain why.
- Your task is specific. Your app combines a model, a prompt, retrieved documents, tools, and post-processing. A benchmark tests none of that combination.
- Your inputs are different. Real users write typos, paste logs, mix languages, and ask things you did not anticipate. Benchmark inputs are cleaner and follow a narrow style.
- Your success criteria are different. A benchmark may reward a correct answer. Your app may also need a specific tone, a length limit, a citation to your own docs, or a refusal on certain topics.
- Benchmarks leak. Popular benchmarks often appear in model training data, so a high score can reflect memorization. Your private dataset is much less likely to have been seen.
- Benchmarks do not change when you do. Your product changes its prompts, documents, and policies. Only a dataset you maintain tracks those changes.
Public benchmarks are still useful for a first model shortlist. They are a poor substitute for measuring your own app.
Why spot checks fail
Most teams start by trying a handful of prompts and reading the answers. This is a sensible first step, but it breaks down in predictable ways.
| Failure of spot checking | What happens |
|---|---|
| Small, hand-picked samples | You test the examples you already thought of, which tend to be the ones that work. |
| No memory | You cannot tell whether a fix for one input broke another you checked last week. |
| Nondeterminism | LLM output varies between runs, so one good answer proves little. |
| Subjective judgment | Two reviewers disagree, and the same reviewer judges differently on a tired afternoon. |
| No numbers | "Seems better" cannot be compared, tracked, or used as a release gate. |
An evaluation dataset addresses each row. The cases are fixed, so results are comparable. There are many cases, so one lucky answer does not dominate. Grading rules are written down, so judgments are consistent. The output is a score with a measurable uncertainty.
Typical failure modes the dataset should catch
The dataset is only useful if it can detect the ways your app actually fails. Common ones include:
- Factual errors and hallucinations. The app states something unsupported, such as a return window that does not exist.
- Regressions. A prompt edit, model upgrade, or retrieval change improves one area and quietly breaks another.
- Format violations. The output should be valid JSON, or under 100 words, and sometimes it is not.
- Policy violations. The app answers something it should refuse, or refuses something it should answer.
- Brittleness. A small rewording of the same question produces a different, wrong answer.
- Edge and adversarial inputs. Empty input, very long input, prompt-injection attempts, and ambiguous requests.
- Uneven quality across groups. The average looks fine while one language, product line, or user type performs badly.
The last item matters most for design. An overall average hides weak spots, so cases need tags that let you report scores per slice (a subset of cases sharing a property). The tutorial builds this up in later chapters.
What evaluation looks like end to end
The workflow in this tutorial follows a loop. You define success, collect and label cases, choose graders, run the app, read per-slice results, and feed new failures back into the dataset.
Each later chapter covers one step of this loop. This chapter explains why the loop is worth the effort.
A minimal eval, to make the idea concrete
The following code is a small but complete eval harness. It loads a JSONL file, rejects duplicate ids, grades each output by exact match, and reports accuracy per tag. Here app is any function that maps an input string to an output string.
import json
from collections import defaultdict
def load_cases(path):
with open(path, encoding="utf-8") as f:
cases = [json.loads(line) for line in f if line.strip()]
ids = [c["id"] for c in cases]
assert len(ids) == len(set(ids)), "duplicate case ids"
return cases
def grade(output, reference):
return output.strip().lower() == reference.strip().lower()
def run_eval(cases, app):
by_tag = defaultdict(list)
for c in cases:
ok = grade(app(c["input"]), c["reference"])
for tag in c["tags"]:
by_tag[tag].append(ok)
return {tag: sum(v) / len(v) for tag, v in by_tag.items()}A few design points are already visible here.
- The duplicate-id check exists because ids are how you track a case across versions. Two cases with the same id make results ambiguous.
- Exact match is the simplest grader. It works only when the correct output is tightly constrained. For free-form answers you will need other graders, which a later chapter compares.
- Results are grouped by tag, so one case can count toward several slices.
- A case with no
tagskey would raise aKeyError. A production harness should validate the schema when loading.
Suppose you run this on 40 cases and get {"returns": 0.9, "policy": 0.9, "shipping": 0.5}. The overall average might look acceptable, but the shipping slice shows a real problem. Without tags you would not see it.
Two caveats about scores
A score from a small dataset is an estimate, not a fact. If 18 of 20 cases pass, the true pass rate could plausibly be well above or below 90%. The chapter on dataset size shows how to put a confidence interval around the number. Until then, treat differences of a few points between two runs on a small dataset with suspicion.
A score is also only as good as its grader. If the reference answers are wrong, or the grader is too lenient or too strict, the number looks precise while measuring the wrong thing. Later chapters cover annotator agreement and judge calibration for this reason.
What you will build in this tutorial
By the end, you will be able to do the following.
- Define task-specific success criteria that can be checked on individual cases.
- Design a schema with inputs, references, tags, and provenance.
- Collect cases from production logs, expert writing, and synthetic generation.
- Cover common, edge, and adversarial inputs with tagged slices.
- Label cases and measure how well annotators agree.
- Choose code-based, human, or LLM-judge graders, and calibrate a judge.
- Split data to avoid leakage and estimate uncertainty.
- Version the dataset and grow it from observed failures.
- Run an evaluation and report per-slice scores.
Exercise
Your support bot scores 92% overall on a 50-case dataset. After a prompt change it scores 93%. A teammate says the change is an improvement and ships it. Give two reasons this conclusion may be unjustified, and one thing you would check in the dataset.
Show answer
First, a one-point difference on 50 cases is one case, well within run-to-run noise from nondeterministic output and sampling uncertainty, so the change may not be real. Second, the overall average can hide a regression in one slice, for example a drop in shipping questions offset by a gain in returns. Check the per-slice scores (and which individual cases changed) using the tags, and compute a confidence interval or rerun several times to see the noise level.
Exercise
Name three reasons a public benchmark does not replace your own evaluation dataset.
Show answer
Any three of: the benchmark does not test your specific combination of prompt, retrieval, and tools; its inputs differ from your real user traffic; its success criteria differ from yours (tone, format, citations, refusals); it may have leaked into model training data; and it does not change as your product and policies change.