Evaluation Harnesses and Reproducibility › Executing a Run and Recording Artifacts
Language AI HandbookAll chapters For each task, archive its ID, rendered messages, raw response, extracted answer, reference, score and status. The fixture rejects duplicate IDs before execution. Preserve raw inputs and outputs only under appropriate access and retention settings.
Retaining raw responses lets a later grader score the same outputs. Keep the original scores too so you can compare the two decisions.
PythonIn [12]Expand
@dataclass(frozen=True)
class ItemRecord:
item_id: str
messages: list[dict]
response: str
extracted: str | None
reference: str
score: float
status: str
def run_eval(
model, prompt, grader, temperature, items, backend_revision="mock-backend-1"
):
if len({x["id"] for x in items}) != len(items):
raise ValueError("Evaluation item IDs must be unique.")
records = []
for item in items:
messages = prompt.render(item["question"])
response = model.generate(messages, item, temperature, backend_revision)
extracted = grader._extract(response)
score, status = grader.grade(response, item["answer"])
records.append(
ItemRecord(
item["id"],
messages,
response,
extracted,
item["answer"],
score,
status,
)
)
return recordsPythonIn [13]Expand
records_a = run_eval(model_a, prompt, grader, model_a_cfg.temperature, dataset)
records_b = run_eval(model_b, prompt, grader, model_b_cfg.temperature, dataset)ConsoleOut [14]Expand
Model A (small): 5/8 correct = 0.625 statuses={'graded': 7, 'bad_reference': 1}
Model B (large): 6/8 correct = 0.750 statuses={'graded': 7, 'bad_reference': 1}Both runs produce a per-item accuracy, but the fixture's m04 has a broken reference and is scored bad_reference with 0. This is a fixture bug we introduced deliberately. The harness caught it via status, and a careful reviewer would exclude or fix m04 before reporting. For the statistics below, we will drop items with bad_reference so the denominator is well defined. That exclusion decision is itself part of the reporting convention and must be documented. The reason it must be documented is that exclusions change the denominator, and a silent exclusion is indistinguishable from a score improvement: if you drop a hard item, the accuracy goes up and the number looks better, even though nothing about the model changed.
PythonIn [15]Expand
def graded_only(records):
return [r for r in records if r.status != "bad_reference"]
rec_a = graded_only(records_a)
rec_b = graded_only(records_b)
scores_a = np.array([r.score for r in rec_a])
scores_b = np.array([r.score for r in rec_b])
n = len(rec_a)
assert len(rec_b) == nBefore trusting either accuracy, it helps to see the raw per-item score structure and how the status audit changes the denominator. The plot below shows each model's graded hit fraction next to the true capability and flags the one excluded item, so the reader can see exactly which denominator the reported number uses.
PythonIn [16]Expand
_graded_fraction_by_model = [
(
"A",
float(scores_a.mean()),
model_a.success_probability(model_a_cfg.temperature),
len(scores_a),
len(records_a) - len(scores_a),
),
(
"B",
float(scores_b.mean()),
model_b.success_probability(model_b_cfg.temperature),
len(scores_b),
len(records_b) - len(scores_b),
),
]VisualizationOut [17]Expand

Align the two score arrays by task ID before subtracting them. The assertion checks that the retained rows identify the same tasks in the same order.
PythonIn [18]Expand
ids_a = [r.item_id for r in rec_a]
ids_b = [r.item_id for r in rec_b]
assert ids_a == ids_b, "items must be aligned for paired statistics"
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!