Sub topic 13
Version and store the dataset
This chapter assumes you can read and write JSONL files in Python, use Git at a basic level, and know the test case schema and the dev/test split from earlier chapters. By the end you will be able to store an evaluation dataset so that any past score can be reproduced, and so that every change to the dataset is visible and explainable.
Why a dataset needs versions
An evaluation score only means something relative to the data it was computed on. Suppose accuracy was 82% last month and is 78% today. Three things could explain the drop:
- The app got worse.
- Someone added harder cases.
- Someone fixed wrong reference answers.
Without a record of what the dataset looked like on each run, you cannot tell these apart. Versioning gives you that record.
A versioned dataset gives you three abilities:
- Reproduce a run. You can re-run an old model against the exact cases it was scored on.
- Compare fairly. Two scores are comparable only if they came from the same dataset version.
- Audit changes. You can answer who changed a reference answer, when, and why.
What to store
Treat the dataset as a small package of files, not a single file.
| File | Purpose |
|---|---|
| `cases.jsonl` | One case per line, using the schema from the schema chapter |
| `manifest.json` | Version number, content hash, case counts, and split rule |
| `CHANGELOG.md` | Human-readable list of what changed in each version |
| `rubrics/` | Grading rubrics and judge prompts that the labels depend on |
Keep the rubrics and judge prompts with the data. A reference answer is only valid under the rubric it was written for. If the rubric changes and the dataset version does not, old and new scores are silently incomparable.
Choosing where the data lives
Most evaluation datasets are small: hundreds to a few thousand cases, which is well under a few megabytes. That makes the storage choice simple.
| Option | Good for | Watch out for |
|---|---|---|
| JSONL in the same Git repo as the app | Small datasets, code review of changes, tags that match app releases | Large attachments such as PDFs or images bloat the repo |
| Git LFS or DVC with object storage | Datasets with large files, such as documents or screenshots | An extra tool to install, and pointers that can break if the remote is cleaned up |
| A database table | Many annotators editing at once, a labeling UI | History is not automatic, so you must export snapshots |
| A shared spreadsheet | Early drafting by non-engineers | No stable history, easy accidental edits, so export before use |
A good default is JSONL in Git, with large files referenced by path or URL in a field of the case. Git diffs on JSONL are readable because each case is one line, so a reviewer sees exactly which cases changed.
Write the file in a stable form so diffs stay small. Use one key order, UTF-8, and one trailing newline. Sort lines by id when you save. A tool that rewrites the whole file in a different order creates a diff that nobody can review.
Stable ids and immutable cases
The id field is what ties everything together: the split assignment, the per-case results history, and the diffs. Three rules keep it useful:
- Never reuse an id. If you delete
refund-014, the next case isrefund-0xx, not a newrefund-014. - Never change an id. A renamed id looks like a delete plus an add, and it also changes the hash-based split, which can move a case from dev to test.
- Do not edit a case in place without recording it. If you change the input of a case, the old results for that id no longer describe the same task. Retire the old id and add a new one. If you only fix a typo in the reference, edit in place and log it in the changelog.
Add an optional status field (active or retired) rather than deleting lines. Retired cases stay in the file for history, and the loader skips them.
Hash the content, record it in a manifest
A version number is a label a person chooses. A content hash is computed from the data, so it detects any change, including one nobody remembered to log. Store both.
The code below computes a hash that does not depend on line order, key order, or whitespace. It then writes a manifest that includes per-split counts, using the same split_for rule as the split chapter.
import hashlib
import json
from collections import Counter
from pathlib import Path
def split_for(case_id, test_percent=20):
digest = hashlib.sha256(case_id.encode("utf-8")).hexdigest()
return "test" if int(digest, 16) % 100 < test_percent else "dev"
def read_cases(path):
lines = Path(path).read_text(encoding="utf-8").splitlines()
return [json.loads(line) for line in lines if line.strip()]
def dataset_hash(cases):
h = hashlib.sha256()
for case in sorted(cases, key=lambda c: c["id"]):
line = json.dumps(case, sort_keys=True, ensure_ascii=False,
separators=(",", ":"))
h.update(line.encode("utf-8"))
h.update(b"\n")
return h.hexdigest()
def write_manifest(cases_path, version, manifest_path="manifest.json"):
cases = read_cases(cases_path)
active = [c for c in cases if c.get("status", "active") == "active"]
splits = Counter(split_for(c["id"]) for c in active)
manifest = {
"version": version,
"sha256": dataset_hash(cases),
"total_cases": len(cases),
"active_cases": len(active),
"splits": dict(splits),
"split_rule": "sha256(id) % 100 < 20 -> test",
}
Path(manifest_path).write_text(
json.dumps(manifest, indent=2) + "\n", encoding="utf-8"
)
return manifestRun write_manifest("cases.jsonl", "1.0.0") and commit the manifest in the same commit as the data. A CI check can recompute the hash and fail if it differs from the manifest. That catches edits made without a version bump.
Choosing a version number
Use a three-part number, MAJOR.MINOR.PATCH, with meanings adapted to datasets:
- PATCH: fixes that should not move scores much, such as a typo in a reference or a corrected tag.
- MINOR: cases added, or retired for being obsolete. Existing cases keep their meaning, so scores on the old cases remain comparable.
- MAJOR: a change in what is being measured, such as a new rubric, a new grading method, or a new success definition. Scores before and after this change must not be compared directly.
When you bump MAJOR, re-run the previous best model on the new version so you have a fresh baseline.
See exactly what changed between versions
Before you release a version, produce a diff by id. This catches accidental changes and gives you the text for the changelog.
import json
def diff_versions(old_cases, new_cases):
old = {c["id"]: c for c in old_cases}
new = {c["id"]: c for c in new_cases}
added = sorted(new.keys() - old.keys())
removed = sorted(old.keys() - new.keys())
changed = sorted(
cid for cid in old.keys() & new.keys()
if json.dumps(old[cid], sort_keys=True) != json.dumps(new[cid], sort_keys=True)
)
return {"added": added, "removed": removed, "changed": changed}
old = [{"id": "a", "input": "x", "reference": "1"},
{"id": "b", "input": "y", "reference": "2"}]
new = [{"id": "a", "input": "x", "reference": "1"},
{"id": "b", "input": "y", "reference": "3"},
{"id": "c", "input": "z", "reference": "4"}]
print(diff_versions(old, new))This prints {'added': ['c'], 'removed': [], 'changed': ['b']}. A removed list that is not empty should make you stop. With the retire-instead-of-delete rule, ids should disappear from the file only in rare cases, and you should be able to say why.
Release flow
The flow below shows how a change moves from proposal to a tagged version that eval runs can reference.
Tie every result to a dataset version
Versioning only pays off if run results record which version they used. Add three fields to every result file your eval runner writes:
dataset_versiondataset_sha256grader_version, which covers the judge prompt, judge model, and any rubric file
Your comparison tooling should then refuse, or at least warn, when two runs have different dataset_sha256 values. Without this check, a leaderboard of scores quietly mixes datasets.
Also store per-case outputs and scores, not only the summary. With per-case records, you can later recompute metrics on the cases that two versions share. That lets you compare a model on version 1.0.0 and version 1.2.0 using only the unchanged cases.
Common errors
- Editing the file and forgetting the version. The CI hash check described above prevents this.
- Regenerating the file from a script with random order. The diff becomes unreadable. Sort by
idon every write. - Changing the split rule. Altering
test_percentor the hash method moves cases between dev and test, which leaks test cases into your tuning work. Treat the split rule as part of the MAJOR version. - Storing the only copy in a personal notebook or a spreadsheet. Keep the canonical copy in the repository or a shared bucket with backups.
- Putting sensitive production data in a public or widely shared repo. Cases taken from logs may contain personal data. Redact them before they enter the file, and restrict repo access to match what remains.
Exercise
Exercise
Your team fixes 12 typos in reference answers, adds 40 new cases for a new "warranty" slice, and then switches the grader from exact match to an LLM judge with a new rubric. What version bump should each change get, assuming the current version is 1.4.2, and why should the final scores not be compared with those from before the grader change?
Show answer
The typo fixes are a PATCH change (1.4.3), since they should not move scores much. Adding 40 cases is a MINOR change (1.5.0), because existing cases keep their meaning. Switching the grader and rubric changes what is being measured, so it is a MAJOR change (2.0.0). Scores before and after use different grading methods, so a difference could come from the grader and not from the app. Re-run the previous model on 2.0.0 to get a new baseline. If all changes ship together, the single release is 2.0.0, and the changelog should list all three changes.