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
LayerWhat it protects againstRuns whenGate
L1 UnitBroken rule logic, rounding, date handling, edge inputs.Every commitHard block
L2 Contract & schemaTool output shape drift, upstream API change, invalid data promoted between layers.Every commit + scheduled against live APIsHard block
L3 ParityAny behavioural difference from the legacy calculation baseline.Every commit touching rulesHard block
L4 RetrievalIndex regressions, chunking changes, superseded documents resurfacing.Every index rebuild + nightlyThreshold
L5 AnswerUngrounded prose, wrong measure selection, missing citations, over-answering.Every prompt/model change + nightlyThreshold
L6 AdversarialPrompt injection from retrieved content, permission probing, jailbreak-style boundary erosion.Before each release + monthlyHard block on leaks
L7 UATMismatch between a technically correct answer and a genuinely useful one.Per release, sampledSign-off
5.2Building the evaluation setImplementation
5.3What CI actually runsImplementation
5.4Observability and the production feedback loopImplementation