Synthetic Data Pipelines › Provenance for Synthetic Corpora
Language AI HandbookAll chapters Record the inputs and decisions needed to check the delivered corpus later.
For this simulator the lineage includes its generator configuration, template definitions and any evaluation fixture item copied. A real pipeline can also record the actual prompt seeds, licenses, and filter decisions.
For exact replay, retain the inputs, generator version, invocation, dependencies, random state and any other conditions that determine output in your setup. A digest can check retained inputs against an expected value. Keep the emitted records so readers can inspect them even when exact replay is impractical.
A structured, machine-readable description of a sample's origin: which generator and revision, which prompt template (by content hash), which decoding configuration, which seeds, which filters ran, and which verification verdicts were issued. Provenance is what distinguishes a dataset from a text dump.
The record schema
Each surviving sample gets one record. The fields below describe what a production schema can capture. The fixture exports an illustrative subset and keeps the rest of its invocation and defaults in the chapter code.
record_idandseq: a stable identifier and position.provenance.generator: model id and revision. "gpt-class-model" is not a revision; a date or a checkpoint hash is.provenance.prompt_template: id plus content hash, so a reader can compare the template bytes against the recorded version.provenance.decoding: retain the effective sampling configuration and seed for replay. The fixture record gives the sampler, temperature, and seed.provenance.parents: the data this record derived from, such as a prompt seed or a copied fixture item.task: the prompt, response, and verified answer.verification: which oracle ran and what it returned.selection: judge scores, cluster assignment, difficulty tier, and the list of filters applied.risk: which safety scans ran, including those that did not run. Recording a scan as"not_run"is more useful than omitting the field, because it tells the next reader what to worry about.
An absent scan field is ambiguous. The reader cannot distinguish a scan that did not run from a missing result. Record whether the scan ran and, if so, retain the result or a reference to it.
PythonIn [41]Expand
records, prev = [], "0" * 64
for seq, (_, row) in enumerate(final.sort_values("row_id").iterrows()):
program = row["program"] if isinstance(row["program"], str) else None
rec = {
"record_id": f"syn-arith-{seq:05d}",
"seq": seq,
"prev_hash": prev,
"provenance": {
"kind": "synthetic",
"generator": {
"model_id": "teacher-sim-1",
"revision": "2025-05-14",
},
"prompt_template": {"id": "arith-v3", "sha256": TEMPLATE_HASH},
"decoding": {
"sampler": "categorical",
"temperature": float(row["temperature"]),
"seed": 1000 + TEMPERATURES.index(float(row["temperature"])),
},
"parents": (
[
{
"kind": "eval-fixture-item",
"fixture_sha256": EVAL_FIXTURE_HASH,
"item_id": row["eval_qid"],
}
]
if isinstance(row.get("eval_qid"), str)
else []
),
"sample_index": int(row["sample_idx"]),
"echo_source_sample_index": (
int(row["source_sample_idx"])
if row["emission"] == "echo"
else None
),
"emission": str(row["emission"]),
"run_id": RUN_ID,
"created_utc": RUN_TS,
},
"task": {
"prompt": str(row["problem"]),
"response": str(row["response"]),
"answer": int(row["ground_truth"]),
},
"verification": {
"method": "parsed-answer-match",
"passed": True,
"answer_source": "template-exec"
if program is not None
else "benchmark-label",
"program": program,
},
"selection": {
"judge_mean": round(float(row["judge_mean"]), 4),
"cluster": int(row["cluster"]),
"tier": str(row["tier"]),
"filters": [
"format",
"answer_match",
"exact_dedup",
f"near_dedup@{NEAR_DUP_THRESHOLD:.2f}",
f"decontam@{DECONTAM_THRESHOLD:.2f}",
"diversity_cap",
],
},
"risk": {"pii_scan": "not_run", "toxicity_scan": "not_run"},
}
rec["record_hash"] = hashlib.sha256(canonical(rec).encode()).hexdigest()
prev = rec["record_hash"]
records.append(rec)Hash chains and manifests
Each record stores the previous record's hash. Its own hash covers that link and the record's contents. Recomputing the record hashes and checking the links detects an unrehashed content edit, an interior deletion, or a reordering. An intact prefix can still pass these local checks after the tail has been removed.
To check the complete artifact, compare the file's hash and row count with a manifest obtained through a trusted channel. A file mismatch identifies the artifact whose bytes differ. A record-level check can also locate a broken link or an unrehashed field edit. The manifest in this example records both the expected row count and the hash of the whole JSONL file.
PythonIn [42]Expand
out_dir = Path("build/synthetic_pipeline")
out_dir.mkdir(parents=True, exist_ok=True)
records_path = out_dir / "records.jsonl"
with records_path.open("w", encoding="utf-8") as f:
for rec in records:
f.write(json.dumps(rec, ensure_ascii=False, sort_keys=True) + "\n")
manifest = {
"run_id": RUN_ID,
"created_utc": RUN_TS,
"generator": {"model_id": "teacher-sim-1", "revision": "2025-05-14"},
"prompt_template": {"id": "arith-v3", "sha256": TEMPLATE_HASH},
"evaluation_fixture_sha256": EVAL_FIXTURE_HASH,
"illustrative_seed_set": {
"sha256": ILLUSTRATIVE_SEED_HASH,
"used_in_generation": False,
"licenses": sorted({s["license"] for s in ILLUSTRATIVE_SEEDS}),
},
"decoding_grid": [
{"temperature": t, "n": N_PER_TEMPERATURE} for t in TEMPERATURES
],
"filters": {
"near_dedup_threshold": NEAR_DUP_THRESHOLD,
"decontamination_threshold": DECONTAM_THRESHOLD,
"decontamination_ngram": 8,
"diversity_cap_per_cluster": cap,
},
"judge_audit": {"threshold": JUDGE_THRESHOLD},
"counts": {stage: int(count) for stage, count in funnel},
"records_file": records_path.name,
"record_count": len(records),
"records_sha256": hashlib.sha256(records_path.read_bytes()).hexdigest(),
"curriculum": {
name: [records[i]["record_id"] for i in idx]
for name, idx in assignments.items()
},
}
(out_dir / "manifest.json").write_text(
json.dumps(manifest, indent=2, sort_keys=True), encoding="utf-8"
)ConsoleOut [43]Expand
records written: 116 records sha256: bd6243a4667133b3a92d5dc7... manifest bytes: 4,281
The example manifest binds the records file and reports stage counts, thresholds, and curriculum assignments. Its seed-license values are illustrative fixture metadata. Replaying the run also requires its generator code, effective invocation, and dependencies.
Verifying, and watching verification fail
The verifier expects well-formed JSONL records with the required fields. A caller should treat JSON parse errors and missing-field errors as verification failures. For schema-valid records, this helper checks each record hash and predecessor link. With an expected manifest it also checks count and file digest. Try it on an edit and a missing final record.
PythonIn [44]Expand
def verify_jsonl(path, expected_manifest=None):
data = Path(path).read_bytes()
lines = data.splitlines()
prev_hash, problems = "0" * 64, []
for line in lines:
rec = json.loads(line)
stored = rec.pop("record_hash")
if rec["prev_hash"] != prev_hash:
problems.append(("chain", rec["record_id"]))
if hashlib.sha256(canonical(rec).encode()).hexdigest() != stored:
problems.append(("hash", rec["record_id"]))
prev_hash = stored
if expected_manifest is not None:
if len(lines) != expected_manifest["record_count"]:
problems.append(("count", Path(path).name))
if (
hashlib.sha256(data).hexdigest()
!= expected_manifest["records_sha256"]
):
problems.append(("file_digest", Path(path).name))
return problems
tampered = [json.loads(json.dumps(r)) for r in records]
tampered[5]["task"]["response"] = "The answer is 999."
tampered_path = out_dir / "records_tampered.jsonl"
with tampered_path.open("w", encoding="utf-8") as f:
for rec in tampered:
f.write(json.dumps(rec, ensure_ascii=False, sort_keys=True) + "\n")
truncated_path = out_dir / "records_truncated.jsonl"
lines = records_path.read_bytes().splitlines(keepends=True)
truncated_path.write_bytes(b"".join(lines[:-1]))ConsoleOut [45]Expand
original with manifest: []
edited with manifest: [('hash', 'syn-arith-00005'), ('file_digest', 'records_tampered.jsonl')]
truncated, chain only: []
truncated with manifest: [('count', 'records_truncated.jsonl'), ('file_digest', 'records_truncated.jsonl')]The original matches the manifest. The edit triggers a record hash error and a file digest error. The truncated prefix passes the chain-only check but fails both the count and file digest checks. A replaced file and a replaced manifest can agree. A verified signature can authenticate the expected manifest if the verifier trusts that the public key belongs to the signer.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!