Evaluation Harnesses and Reproducibility › Writing the Artifact Bundle
Language AI HandbookAll chapters The bundle stores the manifest, dataset, prompt, model configuration, grader, harness policy and item records. Each file has a digest held separately for verification. The fixture uses a temporary directory; a real run would persist the files and trusted digest reference under its artifact policy.
Pass the same ordered tasks to the archive writer that the manifest and evaluator used. Before writing, compare the dataset, prompt, model settings, grader and run policy with their recorded identities. Check that each record matches the corresponding task and rendered messages. The archive keeps the fields needed to reproduce the scores.
PythonIn [19]Expand
def check_bundle_inputs(inputs, records):
manifest = inputs["manifest.json"]
items = inputs["dataset.json"]
prompt = PromptTemplate(**inputs["prompt.json"])
model_config = inputs["model_config.json"]
grader_policy = inputs["grader.json"]
run_policy = inputs["run_policy.json"]
if digest(items) != manifest["dataset_digest"]:
raise ValueError("Dataset content does not match the run manifest.")
identities = {
"prompt_name": prompt.name,
"prompt_version": prompt.version,
"prompt_digest": prompt.template_digest(),
"model_name": model_config["name"],
"model_revision": model_config["revision"],
"model_digest": digest(model_config),
"grader_version": grader_policy["version"],
"grader_digest": digest(grader_policy),
"harness_policy_digest": digest(run_policy),
}
for field, value in identities.items():
if manifest[field] != value:
raise ValueError(
f"Archive {field} does not match the run manifest."
)
ids = [item["id"] for item in items]
if len(ids) != len(set(ids)):
raise ValueError("Archived item IDs must be unique.")
recorded_items = [(row["item_id"], row["reference"]) for row in records]
if recorded_items != [(item["id"], item["answer"]) for item in items]:
raise ValueError(
"Record IDs and references must match the ordered dataset."
)
for item, row in zip(items, records, strict=True):
if row["messages"] != prompt.render(item["question"]):
raise ValueError(f"Rendered messages differ for {item['id']}.")
def write_bundle(manifest, items, records, prompt, model_cfg, grader):
inputs = {
"manifest.json": asdict(manifest),
"dataset.json": items,
"prompt.json": asdict(prompt),
"model_config.json": asdict(model_cfg),
"grader.json": grader.policy(),
"run_policy.json": RUN_POLICY,
}
rows = [asdict(record) for record in records]
check_bundle_inputs(inputs, rows)
payloads = {name: canonical_bytes(value) for name, value in inputs.items()}
payloads["records.jsonl"] = b"".join(
canonical_bytes(row) + b"\n" for row in rows
)
out = ARTIFACT_DIR / manifest.manifest_digest()
out.mkdir(exist_ok=True)
for name, contents in payloads.items():
path = out / name
if path.exists() and path.read_bytes() != contents:
raise ValueError(f"Existing bundle differs at {name}.")
path.write_bytes(contents)
digests = {
name: hashlib.sha256(contents).hexdigest()
for name, contents in payloads.items()
}
return out, digests
path_a, trusted_a = write_bundle(
manifest_a, dataset, records_a, prompt, model_a_cfg, grader
)
path_b, trusted_b = write_bundle(
manifest_b, dataset, records_b, prompt, model_b_cfg, grader
)ConsoleOut [20]Expand
Artifact bundles written: 7f1151443fcc3646... -> ['dataset.json', 'grader.json', 'manifest.json', 'model_config.json', 'prompt.json', 'records.jsonl', 'run_policy.json'] 3488e58bf9e4a874... -> ['dataset.json', 'grader.json', 'manifest.json', 'model_config.json', 'prompt.json', 'records.jsonl', 'run_policy.json']
The stored responses can be scored with the same grader without calling the model again. A later grading policy can generate a separate report over those responses. Report which policy produced each score.
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!