Skip to chapter content
navan✳THE BUILD LABAI ENGINEERING / GUIDE
0/21 read
COOKBOOK 04 / 8

An evaluation report that explains failure.

Score retrieval and answer behavior by slice instead of hiding everything in one average.

BY NAVAN SAMICOMPLETE EXAMPLEPYTHON 3
01 / THE PURPOSE

Why this workflow exists.

A system can look strong on routine questions while failing every unsupported question. Reporting only one average masks that failure. This recipe stores a slice and expected behavior for each case, evaluates results, and groups pass rates by slice.

The check is intentionally narrow: it tests whether the required source was returned or whether the system declined. Content quality would need another rubric or review stage. Keeping the check narrow makes its meaning clear.

Code context. Python 3 standard library only. The small case set is fictional and included in the script.

02 / COMPLETE PYTHON

The whole example.

retrieval-evaluation.py
from collections import defaultdict

cases = [
    {"slice": "routine", "source": "access-1", "result": {"status": "candidate", "sources": ["access-1"]}},
    {"slice": "routine", "source": "billing-2", "result": {"status": "candidate", "sources": ["access-1"]}},
    {"slice": "unsupported", "source": None, "result": {"status": "declined", "sources": []}},
    {"slice": "unsupported", "source": None, "result": {"status": "candidate", "sources": ["billing-2"]}},
]


def passes(case):
    if case["source"] is None:
        return case["result"]["status"] == "declined"
    return case["source"] in case["result"]["sources"]

by_slice = defaultdict(list)
for case in cases:
    by_slice[case["slice"]].append(passes(case))
for name, outcomes in sorted(by_slice.items()):
    print(name, sum(outcomes), "/", len(outcomes))
03 / READ THE FLOW

What each stage does.

Each case pairs an expected source or refusal with a recorded system result. passes checks exactly that expectation. defaultdict groups booleans by slice; True counts as one when summed. The final loop prints pass counts and denominators so a reader sees both successes and sample size.

One routine case cites the right document and one does not. One unsupported case declines and one incorrectly answers. Both slices score one out of two. Those numbers are too small to estimate real performance, but the report shape shows how a larger evaluation should expose different failure types.

04 / THE RESULT

What the output means.

The output shows routine 1 / 2 and unsupported 1 / 2. The report makes the unsafe unsupported answer visible instead of burying it in an overall score.

05 / THE BOUNDARY

Where the example stops.

This check does not evaluate whether the text of a cited answer is faithful to the source. Add claim-support review, format checks, and user-outcome evidence as needed. Keep holdout cases separate from examples used to tune the system.

Built with curiosity. By Navan Sami. ↗AI engineering · From model calls to reliable systems.