Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← Evals and observabilityAI guideBeginner#evals#datasets#error-analysis#annotation
Frame · ai-engineering / evals-observability / 02-golden-datasets-and-error-analysis.mdGuide 050 / 103

Golden datasets and error analysis

Every eval suite is only as good as the examples in it. A golden dataset is a curated, versioned set of inputs (and often reference outputs or labels) that represents what your users actually do and where your system actually breaks. The fastest way to build one is not to brainstorm test cases, it is to read your own traces and write down what goes wrong. That reading process has a name, error analysis, and it is the most underrated skill in AI engineering.

Why it matters

Generic benchmarks tell you how a model does on someone else's problem. Your users have their own vocabulary, edge cases and expectations. Hamel Husain puts it bluntly in his evals FAQ: error analysis is what tells you which evals to write in the first place, because it surfaces failure modes unique to your application and your data.

The practical benefits:

  • You stop writing graders for problems you do not have.
  • You get a prioritised list of failure modes, with counts, so you know what to fix first.
  • Your dataset naturally covers the long tail, because it was sampled from reality.

How it works

The workflow is borrowed from qualitative research. You look at a sample of traces, take free-form notes (open coding), group those notes into categories (axial coding), count them, and repeat until new traces stop teaching you anything new.

Rendering diagram…

Step 1: get traces. If you have production traffic, sample it, ideally stratified by user segment, feature or intent. If you are pre-launch, generate synthetic inputs by defining dimensions (user persona, task type, difficulty) and asking a model to produce combinations, then have a human prune the unrealistic ones.

Step 2: open coding. A domain expert reads each trace and writes a short note about what went wrong, if anything. Hamel's advice is to note the first failure you see in a trace, since upstream mistakes often cause downstream ones. Do not try to fit notes into categories yet. "Ignored the user's date constraint" is a better note than "bad answer".

Step 3: axial coding. Group the notes into a small taxonomy of failure modes. An LLM can help cluster notes, but a human should own the final categories. You end up with something like: wrong tool selected (14), hallucinated policy detail (9), ignored formatting instruction (6), refused a valid request (3).

Step 4: iterate to saturation. Keep reviewing until new traces stop revealing new failure modes. Hamel's rule of thumb is to review at least 100 traces before you trust the taxonomy.

Step 5: turn failure modes into evals. For each mode that matters, add labelled examples to the dataset and choose a grader. Some modes are best caught with code (format, tool name), others need an LLM judge (tone, faithfulness).

A note on ownership: Hamel recommends a single domain expert, which he calls a benevolent dictator, to make the final call on what counts as a failure. Committees produce inconsistent labels.

Reference architecture

Rendering diagram…

Most observability tools have an annotation queue feature (Langfuse and LangSmith both do), but a simple custom review UI is often worth building because it lets you show exactly the context the reviewer needs.

Code

A small script that turns open-coded notes into a ranked failure taxonomy and writes a versioned dataset split. The clustering here is a manual mapping on purpose: the human owns the categories.

import csv
import hashlib
import json
from collections import Counter
from pathlib import Path

# notes.csv columns: trace_id, input, output, note, category
# 'category' is filled in during axial coding (blank means no failure).
rows = list(csv.DictReader(open("notes.csv", newline="")))

counts = Counter(r["category"] for r in rows if r["category"])
total = len(rows)
print(f"Reviewed {total} traces")
for category, n in counts.most_common():
    print(f"{category:40s} {n:4d}  ({n / total:.0%})")

# Build the golden set: every failing trace plus a sample of passing ones.
failing = [r for r in rows if r["category"]]
passing = [r for r in rows if not r["category"]][: len(failing)]

dataset = [
    {
        "id": r["trace_id"],
        "input": r["input"],
        "label": r["category"] or "ok",
        "note": r["note"],
    }
    for r in failing + passing
]

blob = json.dumps(dataset, sort_keys=True).encode()
version = hashlib.sha256(blob).hexdigest()[:8]
out = Path(f"datasets/golden-{version}.json")
out.parent.mkdir(exist_ok=True)
out.write_bytes(blob)
print(f"Wrote {len(dataset)} examples to {out}")

Hashing the content gives you a cheap, honest version identifier. Store it alongside every eval run so you can tell whether a score changed because the system changed or because the dataset did.

Trade-offs and pitfalls

  • Synthetic data that is too clean. Generated inputs tend to be grammatical and on-topic. Real users are neither. Mix in real traces as soon as you have them.
  • Only collecting failures. If the dataset is all hard cases, your pass rate tells you nothing about the common path. Keep a representative slice of normal traffic too.
  • Label drift. As your product changes, what counts as correct changes too. Re-review old labels periodically.
  • Automating too early. Letting an LLM do open coding before a human has built intuition hides the very failures you need to see.
  • Leaking eval data into prompts. If you copy golden examples into few-shot prompts, your scores will look great and mean nothing. Keep a held-out split.
  • Privacy. Production traces can contain personal data. Scrub or get consent before copying them into datasets that live in git or third-party tools.
  • Small-sample noise. A dataset of 40 examples cannot distinguish a 2 percent improvement. Grow the set for the modes you care most about.

Checklist

  • You have reviewed at least 100 traces and written a note for each failure.
  • Failure modes are grouped into a short, named taxonomy with counts.
  • One accountable domain expert owns labelling decisions.
  • The golden dataset mixes failures and normal traffic and has a held-out split.
  • Every dataset version has an ID that is recorded with each eval run.
  • There is a scheduled cadence (weekly works) to sample new traces and update the set.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.