Evaluation Harnesses and Reproducibility › Executing a Run and Recording Artifacts

Michael BrenndoerferDecember 1, 20264 min read
Language AI HandbookAll chapters
Part 57 of 67Dynamic, Interactive, and Agentic Evaluation
Chapter 436Evaluation Harnesses and Reproducibility › Executing a Run and Recording Artifacts
Reading section 6 of 18 · Executing a Run and Recording Artifacts · 4 minSection 6 of 18 · 4 min

Section 6 of 18 · 4 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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]
CollapseExpand
@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 records
PythonIn [13]
CollapseExpand
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]
CollapseExpand
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]
CollapseExpand
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) == n

Before 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]
CollapseExpand
_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]
CollapseExpand
Paired bars for observed accuracy and expected mock probability, with graded and excluded counts in each label.
Both mock systems grade seven tasks and exclude the same malformed reference. Each score is compared with that system’s success probability at the configured temperature.

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]
CollapseExpand
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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy