Tutorial

Evaluating LLM Applications with Golden Datasets

Replace subjective impressions with a versioned set of graded examples, task-appropriate metrics and automated regression tests that run on every prompt change.

On this page

  1. Introduction
  2. Why Vibes Are Not Evaluation
  3. Building a Golden Dataset
  4. Choosing Metrics That Match the Task
  5. Running Evaluations in CI
  6. Comparing Runs and Detecting Regressions
  7. Human Review and Model Graders
  8. Keeping the Dataset Fresh
  9. From Evaluation to Confidence
  10. Common Evaluation Mistakes
  11. Sources

Introduction

Prompt engineering without evaluation is guesswork dressed as craft. You change a sentence, the demo feels better, and you ship a regression that nobody notices until a user complains. The remedy is unglamorous: a fixed set of input and expected output pairs, a metric that matches the task, and a harness that runs the whole set on every change and reports a number you can compare. Building that harness early costs a day and saves weeks of chasing phantom improvements.

Why Vibes Are Not Evaluation

Human judgement on a handful of examples is noisy, unrepresentative and impossible to compare across runs. Two engineers can look at the same output and disagree, and neither remembers last week baseline. A golden dataset replaces recollection with a reproducible measurement, so a change is either better, worse or neutral on a defined set. It also creates accountability: when someone proposes a prompt change, the question becomes what the number did, not how it felt.

import json, hashlib
from pathlib import Path

DATASET = json.loads(Path("evals/golden.json").read_text())
CACHE = Path("evals/.cache"); CACHE.mkdir(exist_ok=True)

def key(prompt_version: str, model: str, input_text: str) -> str:
    h = hashlib.sha256(f"{prompt_version}|{model}|{input_text}".encode()).hexdigest()
    return h[:32]

def run_case(call_model, case: dict, prompt_version: str, model: str) -> dict:
    ck = CACHE / f"{key(prompt_version, model, case['input'])}.json"
    if ck.exists():
        output = json.loads(ck.read_text())["output"]
    else:
        output = call_model(case["input"])
        ck.write_text(json.dumps({"output": output}))
    passed = all(a.lower() in output.lower() for a in case["must_contain"])
    return {"id": case["id"], "category": case["category"], "passed": passed}

Building a Golden Dataset

Start small and real. Collect twenty to fifty representative inputs from logs or stakeholders, covering the common cases, the tricky edge cases and the known failure modes, rather than inventing tidy examples. For each, record the expected output or a rubric describing what a good answer must contain. Label them with the category so you can see which slice regressed, and store the set in version control beside the prompt so both evolve together.

from collections import defaultdict

def evaluate(cases: list[dict], output: dict, tolerance: float = 0.0) -> int:
    scores = defaultdict(lambda: [0, 0])
    for c in output["results"]:
        bucket = scores[c["category"]]
        bucket[1] += 1
        bucket[0] += 1 if c["passed"] else 0
    exit_code = 0
    for cat, (passed, total) in sorted(scores.items()):
        rate = passed / total if total else 0.0
        flag = "OK" if rate >= 1.0 - tolerance else "REGRESSION"
        print(f"{cat:20s} {passed}/{total} ({rate:.0%}) {flag}")
        if flag == "REGRESSION":
            exit_code = 1
    return exit_code  # non zero fails the CI job

Choosing Metrics That Match the Task

The metric must reflect what the task actually requires. Exact match suits classification and extraction where one answer is correct; similarity or containment suits summarisation; rubric or assertion checks suit open ended generation. For retrieval you measure recall and rank quality, for structured output you measure schema validity. Pick a metric that a trivial cheat cannot game, then report it per category rather than as one average that hides a failing slice.

Running Evaluations in CI

Wire the harness into continuous integration so every prompt or model change runs the full set and fails the build when a metric drops beyond a tolerance. Cache model responses keyed by prompt and input to keep cost down, and record the exact model version so results are attributable. Print a compact table of per category scores and the delta against the baseline. A change that improves the average while tanking a critical category should still fail, which is why thresholds are per category.

Comparing Runs and Detecting Regressions

Store each run result with the prompt version, model version, dataset version and timestamp so any two runs can be compared honestly. Diff the outputs per example, not only the aggregate, because an unchanged score can hide two examples that swapped direction. Watch for high variance between reruns of the same configuration, since a noisy metric cannot support decisions; if variance is high, increase the dataset or lower the temperature.

Human Review and Model Graders

For subjective quality, combine automatic checks with periodic human review, and use a capable model as a grader only after validating that its grades agree with human ones on a sample. A grader that disagrees with humans is measuring the wrong thing, so calibrate it and re-check when you change the grader model. Keep human review focused on the cases the automatic metrics cannot judge, which is where a real defect hides.

Keeping the Dataset Fresh

A golden set is a living artefact. Add examples whenever a real failure reaches production so the same bug cannot return unnoticed, and retire examples that no longer reflect the product. Periodically re-sample inputs from current traffic, because a dataset frozen two years ago measures a product you no longer ship. Track its growth and refresh cadence as part of the evaluation process, not as an occasional cleanup.

From Evaluation to Confidence

Evaluation exists to make decisions safe. With a trusted harness you can change a prompt, swap a model or adjust retrieval and know within minutes whether the change helps, harms or does nothing, instead of waiting for user complaints. That confidence compounds: you ship smaller and more frequent improvements because each is cheap to verify, and you can hold a quality floor while chasing speed or cost savings. Without it every change is a leap, and teams respond by freezing the prompt, which is the real price of skipping evaluation.

Common Evaluation Mistakes

The most common mistake is evaluating with the same examples used to design the prompt, which measures memorisation rather than generalisation, so hold out a portion the prompt author never saw. The second is chasing a single aggregate number while a category quietly collapses. The third is changing the dataset and the prompt in the same commit, which makes the result impossible to interpret. The fourth is trusting a model grader without calibration. Avoid all four by keeping the dataset independent, reporting per category, changing one thing at a time, and validating any automatic grader against human labels.

Sources

Sources: OpenAI evals, Ragas evaluation, Hugging Face evaluate.

FAQ

How large should a golden dataset be?
Start with twenty to fifty real examples that cover common cases and known failures. Grow it as production failures appear; breadth matters more than a single large number.
Can I use an LLM to grade outputs?
Yes, after validating that its grades agree with human labels on a sample. Re-calibrate whenever the grader model changes, and keep human review for cases the automatic checks cannot judge.

Related Examples