05 — Quality & evaluation
If you cannot score it on demand, you cannot safely change it.
An AI-bearing system degrades quietly — a prompt edit, a model version, a rebuilt index — without a single error. The countermeasure is an evaluation suite that runs like a test suite and gates releases like one.
5.1
The testing pyramid for an AI-native system
Cheap, deterministic tests at the base; expensive, judgement-based tests at the top. L2–L7 are additions relative to conventional delivery.
L1 Unit tests
Pure logic, rules, utils — every commit, hard block.
L2 Contract & schema
Tool I/O, API contracts, data-quality assertions.
L3 Golden-master parity
Historical corpus replay, per-field tolerance.
L4 Retrieval evaluation
recall@k, precision, correct-version cited.
L5 Answer evaluation
Groundedness, numeric exactness, citations, refusal precision.
L6 Adversarial / red team
Injection, leading questions, permission probing.
L7 UAT with real users
Qualitative, per release, sampled.
▸Layer-by-layer: what it protects against, and the gate
| Layer | What it protects against | Runs when | Gate |
|---|---|---|---|
| L1 Unit | Broken rule logic, rounding, date handling, edge inputs. | Every commit | Hard block |
| L2 Contract & schema | Tool output shape drift, upstream API change, invalid data promoted between layers. | Every commit + scheduled against live APIs | Hard block |
| L3 Parity | Any behavioural difference from the legacy calculation baseline. | Every commit touching rules | Hard block |
| L4 Retrieval | Index regressions, chunking changes, superseded documents resurfacing. | Every index rebuild + nightly | Threshold |
| L5 Answer | Ungrounded prose, wrong measure selection, missing citations, over-answering. | Every prompt/model change + nightly | Threshold |
| L6 Adversarial | Prompt injection from retrieved content, permission probing, jailbreak-style boundary erosion. | Before each release + monthly | Hard block on leaks |
| L7 UAT | Mismatch between a technically correct answer and a genuinely useful one. | Per release, sampled | Sign-off |
5.2Building the evaluation setImplementation
5.3What CI actually runsImplementation
5.4Observability and the production feedback loopImplementation