Evaluation-Driven Development › Implementation: Assembling the Harness
Language AI HandbookAll chapters The harness stores the suite digest, grader version, configuration, traces, slice scores, and taxonomy counts. The report exposes which evidence produced the gate's decision.
PythonIn [38]Expand
@dataclass
class RunReport:
suite_version: str
grader_version: str
config: dict
traces: list[Trace]
aggregate: dict
slices: dict
taxonomy: dict
def evaluate(cases: list[Case], config: dict) -> RunReport:
traces = [run_case(c, config) for c in cases]
case_map = {c.case_id: c for c in cases}
tax = Counter(classify(t, case_map[t.case_id]) for t in traces)
return RunReport(
suite_version=suite_hash(cases),
grader_version="substring-v1",
config=config.copy(),
traces=traces,
aggregate=aggregate(traces),
slices=by_slice(traces, cases),
taxonomy=dict(tax),
)PythonIn [39]Expand
baseline_report = evaluate(dev_cases, config={})
print("Suite:", baseline_report.suite_version)
print(
"Aggregate:",
{
k: round(v, 2) if isinstance(v, float) else v
for k, v in baseline_report.aggregate.items()
},
)
print("Taxonomy:", baseline_report.taxonomy)ConsoleOut [39]Expand
Suite: b9dd6a7f0439c284f4cdf4ccc8ab9add604ccf4cb22be9c4c683e3355c7cc8d1
Aggregate: {'n': 4, 'mean': 1.0, 'passes': 4}
Taxonomy: {'pass': 4}Now the gate accepts a pair of reports rather than raw traces, so the harness is the single source of truth. We compare a candidate against the stored baseline and print a human-readable verdict fit for a pull request.
PythonIn [40]Expand
def gate_reports(
baseline: RunReport, candidate: RunReport, cases: list[Case], **kw
) -> GateResult:
if (
baseline.suite_version != candidate.suite_version
or baseline.suite_version != suite_hash(cases)
):
return GateResult(False, ["Suite version changed"])
if baseline.grader_version != candidate.grader_version:
return GateResult(False, ["Grader version changed"])
return regression_gate(baseline.traces, candidate.traces, cases, **kw)PythonIn [41]Expand
candidate_report = evaluate(dev_cases, config={"wrong_window": True})
verdict = gate_reports(baseline_report, candidate_report, dev_cases)
print(
"Suite versions match:",
baseline_report.suite_version == candidate_report.suite_version,
)
print("Gate passed:", verdict.passed)
for r in verdict.reasons:
print(" -", r)ConsoleOut [41]Expand
Suite versions match: True Gate passed: False - Aggregate fell 0.250 - Slice 'billing' fell 1.000 - Regression on case c002
The gate first checks the suite version of both reports and the submitted case list. It also checks that the reports used the same grader version. This prevents those differences from being reported as the candidate's effect.
Reading the summary the way a reviewer would
Show the version, aggregate mean, slice means and denominators, taxonomy counts, and the gate result together.
PythonIn [42]Expand
def review_summary(base: RunReport, cand: RunReport, gate: GateResult) -> str:
lines = [
f"suite={base.suite_version}",
f"grader={base.grader_version}",
f"aggregate {base.aggregate['mean']:.2f} -> {cand.aggregate['mean']:.2f}",
]
for name, before in base.slices.items():
after = cand.slices.get(name)
candidate_label = (
"missing"
if after is None
else f"{after['mean']:.2f} (n={after['n']})"
)
lines.append(
f" {name:14s} {before['mean']:.2f} (n={before['n']}) -> {candidate_label}"
)
lines.append(f"taxonomy {base.taxonomy} -> {cand.taxonomy}")
lines.append(f"gate={'PASS' if gate.passed else 'FAIL'}")
lines.extend(f" - {reason}" for reason in gate.reasons)
return "\n".join(lines)PythonIn [43]Expand
print(review_summary(baseline_report, candidate_report, verdict))ConsoleOut [43]Expand
suite=b9dd6a7f0439c284f4cdf4ccc8ab9add604ccf4cb22be9c4c683e3355c7cc8d1
grader=substring-v1
aggregate 1.00 -> 0.75
multilingual 1.00 (n=1) -> 1.00 (n=1)
technical 1.00 (n=2) -> 1.00 (n=2)
billing 1.00 (n=1) -> 0.00 (n=1)
taxonomy {'pass': 4} -> {'pass': 3, 'forbidden_text': 1}
gate=FAIL
- Aggregate fell 0.250
- Slice 'billing' fell 1.000
- Regression on case c002A reviewer can match each displayed slice mean to its case count and read the labels before opening individual traces. The summary displays the same verdict and reasons returned by the gate for the chosen policy.
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!