A renamed field cut a classifier's recall from 0.90 to 0.78, and every test stayed green. One detector misses it for weeks. Another fires within the hour.
Pick a detector, then press Ship the rename. Watch when its alarm fires and count the violations that slip through first. Then we build, piece by piece, the statistical gate, the tolerance window, drift and data checks, the canary, the tail gate, and a way to grade the gate itself.
You need recall and a confidence interval (see Metric Design and The Statistics of Evaluation) and a little Python. We build the rest from zero.
Illustrative scenario: 500 violating uploads a day, recall 0.90 before the rename and 0.78 after. The detection delays (an hour, a day, three weeks) are typical orders, not measurements.
Chapter 0
Follow a regression that no test sees, and measure how loud it was
A video platform runs a classifier that flags violating uploads. It catches 90 of every 100 violations: its recall (the share of true positives it finds) is 0.90. On a Tuesday, another team renames the field audio_transcript to asr_text.
The feature code still asks for the old name and gets nothing. It fills the gap with zeros for the 40% of uploads that have speech. Nothing crashes. Every request returns HTTP 200. Every unit test passes, because the code runs fine on the wrong data.
A regression is any change that makes the system worse for users, with or without a code change. On the 60% of uploads that keep the transcript, recall stays 0.90. On the 40% that lose it, recall falls to 0.60. The dashboard shows the traffic-weighted blend:
At 500 violations a day, misses rise from 50 to 110. Over three weeks that is 60 × 21 = 1,260 extra violating videos online. Was the drop loud enough to see in one day? Label 500 positives a day and measure recall. The standard error is the typical size of the day-to-day wobble in that measured rate.
S-E equals the square root of p times one minus p, over n.
Multiply p by one minus p. Divide by n. Take the square root. Then divide the drop by SE to see how many wobbles deep it is.
With the made-up incident: p = 0.90, n = 500. SE = √(0.09 / 500) = 0.0134. The drop 0.12 is 0.12 / 0.0134 = 8.9 standard errors. One day of labels would have shown it.
Blue is the spread of a healthy day's measured recall. Orange is a broken day. Pink is the alarm line, 3 standard errors below 0.90. Shrink the affected share and the labeled sample until the bells overlap.
Recall on the affected slice is fixed at 0.60. The bells use the normal approximation to the binomial.
The failure. Symptom: users complain while uptime, latency and CI stay green. Measure: compute the quality metric on a small labeled slice every day. Fix: watch the quantity that fails, not only the quantity that is easy to watch.
Real teams meet this too. In September 2025 Anthropic described three infrastructure bugs that degraded some Claude responses from August into September. Its evaluations "simply didn't capture the degradation users were reporting".
Chapter 1
Map each regression surface to the test layer that can see it
The rename was a data regression. Data is one of five regression surfaces: places where behavior can change. Only one of them shows up as a diff in your repository.
| Surface | How it goes wrong | Layer that sees it |
|---|---|---|
| Code | a library bump changes image resizing from bilinear to nearest | unit and integration tests |
| Data | a vendor sends feet in place of meters | data checks, live monitors |
| Model | a retrain drops 3 points on non-English uploads | golden-set gate |
| Infra | a quantized build drifts from the checkpoint | integration on real serving, canary |
| Prompt | a system prompt edit breaks output parsing for 3% of cases | golden-set gate, live monitors |
The ML test pyramid stacks five layers: unit tests at the bottom, then data tests, model tests, integration tests, and online tests at the top. The bottom layers are exact and run on every commit in seconds. The top layers are statistical and need samples, time or live traffic.
Each bar is the chance the suite catches a regression on that surface. Switch a layer off and see which bars fall. Press Run 100 releases to drop real regressions through.
Illustrative catch rates per layer and surface, chosen so the full suite catches code 0.9, model 0.8, data 0.7, infra 0.6 and prompt 0.5.
With made-up numbers: 100 releases a quarter, 8% carry a real regression, spread evenly over the five surfaces. The miss rates are 0.1, 0.2, 0.3, 0.4 and 0.5, so the average miss is 1.5 / 5 = 0.30. Expected escapes: 8 × 0.30 = 2.4 a quarter. Raise prompt coverage to 0.8 and the average miss becomes 0.24, so escapes fall to 1.92. The weakest layer sets the escape rate.
The failure. Symptom: the team adds unit tests after every incident and incidents continue. Measure: tag each past incident by surface. Fix: spend on the surface with the highest miss rate, usually data or prompt.
Chapter 2
Decide ship or block from the interval of the difference, using only the examples where the two models disagree
The candidate scores 84.7% on the golden set. The baseline scores 86.2%. Ship or block? You cannot answer without the noise. A golden set is a fixed, versioned, labeled set that every release must pass. Keep two kinds: a sampled set drawn at random from traffic, for the statistics, and a curated set of past incidents, as zero-tolerance tripwires.
Run both models on the same n examples. You get two arrays of right-or-wrong, each of shape (n,). Count the disagreements: call b the examples the baseline gets right and the candidate gets wrong, and c the reverse. Examples both get right, or both get wrong, carry no news about which is better.
d equals c minus b, over n; and S-E equals the square root of b plus c, over n.
Subtract b from c and divide by n to get d. Take the square root of b plus c and divide by n to get SE. The interval is d plus or minus 1.96 times SE. Block if its lower end is below minus delta, the largest drop you accept.
With made-up counts: n = 1,000, b = 40, c = 25. d = −15 / 1,000 = −0.015. SE = √65 / 1,000 = 0.0081. Interval: −0.015 ± 0.0158 = [−0.031, +0.001]. With delta 0.01, the lower end −0.031 is below −0.01, so block.
Each run is one paired evaluation: teal dot, purple interval. Pink is the block line at minus delta. Set the true difference to 0, then shrink n and watch good releases get blocked.
Simulated with a disagreement rate of 6.5%. Each run draws b and c at random, so tallies vary by a few points.
How big must n be? To pass a truly equal candidate 80% of the time, delta must be at least (1.96 + 0.84) standard errors wide:
Here pdis is the share of examples where the models disagree and δ (delta) is the margin, 0.01. A 1,000-example set passes an equal candidate only about 24% of the time.
The failure. Symptom: the gate blocks most releases, good or bad. Measure: the interval width, 3.92 × SE, against delta. Fix: grow the set toward the n above. Version it by hash, refresh it from traffic, and never add examples chosen because the candidate fails them.
Chapter 3
Measure run-to-run noise and set the tolerance window from it
The gate blocked a release on Tuesday. Someone pressed retry, and it passed on Wednesday. Same model, same set, same code. The number moved because the evaluation itself is noisy.
| Source | What moves |
|---|---|
| Training seed | initial weights, data order and dropout, so a retrain is a different model |
| GPU arithmetic | the order of a sum changes its last bits, and the order depends on the batch |
| Sampling | temperature above 0 draws a different output per run |
| Harness | unpinned data order, timeouts, a judge model that its provider updates |
Temperature 0 does not fix the GPU row. In September 2025, Thinking Machines Lab sent one prompt 1,000 times at temperature 0 and got 80 different completions. The cause was batch size: the server load changes it, and kernels sum in a different order for each size.
The candidate equals the baseline. Teal dots are single runs; the orange line is their mean, with its purple band. Pink edges mark the window. Press Run 10 and count the runs outside.
Each run draws a score from a bell curve around a true 81.0. The flake rates in the read-out are exact for that bell curve.
Run the artifact k times. The mean of k runs wobbles less than one run. Name the run-to-run standard deviation s and the standard error you want SE*.
k equals s over S-E star, squared.
The mean of k runs has standard error s over the square root of k. Divide s by SE-star and square it: that is the k that reaches the target.
With made-up runs 0.812, 0.798, 0.805, 0.821, 0.784: mean 0.804, s = 0.0141. For SE* = 0.005: k = (0.0141 / 0.005)² = 7.9, so 8 runs.
Those five runs give the interval 0.804 ± 2.776 × 0.0063 = [0.787, 0.821]. The baseline, 0.810, sits inside. Yet the single run 0.784 looks like a 2.6-point regression.
The failure. Symptom: blocks that pass on retry. Measure: the retry-pass rate, and s from 5 to 10 reruns. A window of ±0.5 against s = 1.4 flags 72% of equal runs. Fix: pin what you can, set the window from s, and gate on the mean of k runs.
Chapter 4
Score how far today's data moved from the baseline, and know what drift cannot see
A fraud label arrives when the chargeback does, weeks later. The inputs arrive now. Drift detection compares today's input distribution with a frozen baseline, so an alarm can come weeks before the labels. It sees some kinds of drift and not others.
| Drift | What changes | Input monitor sees it? |
|---|---|---|
| Covariate | the inputs, p(x): a campaign brings younger users | yes |
| Prior | the label mix, p(y): violations double in an election | partly |
| Concept | the meaning, p(y | x): fraudsters adapt | no; only labels show it |
The Population Stability Index (PSI) scores one feature. Cut the baseline into 10 bins that each hold 10% of it. Call the baseline share in bin i ei (expected) and today's share ai (actual).
P-S-I equals the sum over i of a-i minus e-i, times the natural log of a-i over e-i.
For each bin, take today's share minus the baseline share. Multiply by the log of their ratio. Add the 10 terms. Rank the terms to see which bins moved.
With made-up shares 0.06, 0.07, 0.09, 0.10, 0.11, 0.12, 0.13, 0.12, 0.11, 0.09: bin 1 adds (−0.04) × ln 0.6 = 0.0204, bin 2 adds 0.0107. All ten sum to PSI = 0.050. Bins 1 and 2 give 62% of it.
Blue outlines are the baseline deciles. Orange bars are today. Teal bars below are each bin's PSI term. Shift and spread the live data, then press Replay incident.
Baseline is a bell curve. The incident sets 40% of values to zero, as the rename did. PSI and KS are exact for these shapes, not sampled.
The rule of thumb says PSI under 0.10 is stable and over 0.25 is a large shift. The Kolmogorov-Smirnov (KS) statistic D is the largest gap between the two cumulative shares; here D = 0.08. With 5,000 rows a side, the 5% critical value is 1.358 × √(2/5,000) = 0.027. KS calls the shift certain; PSI calls it stable. KS measures detectability and PSI measures size, so at scale, gate on D or PSI, not on the p-value.
The failure. Symptom: 400 features, a flood of alerts, and the real incident had none. Measure: each feature's own week-to-week PSI history. Fix: alert on multiples of that history, rank by PSI times feature importance, and add a labeled slice for concept drift.
Chapter 5
Write expectations for every batch, and set each tolerance from sampling noise
Drift asks whether a distribution moved. Data validation asks a blunter question first: does this batch break a rule? It is unit testing for data: a list of expectations that runs on every batch. A null-rate check would have caught the rename in the first batch.
| Expectation | Example of a violation |
|---|---|
| Schema | a column is missing or renamed |
| Range | distances 3.28 times too large after a feet-for-meters swap |
| Null rate | a feature that is 2% null is 27% null today |
| Freshness | the server still reads yesterday's partition |
| Volume | a dedup bug halves the row count |
| Cross-field | end_time comes before start_time |
A null rate is a measured rate, so it wobbles. A rule like "fail above 2%" fires on about half of healthy batches. Score today's rate against its own noise. Call the baseline null rate p, the batch size n, and today's null rate r.
z equals r minus p, over the square root of p times one minus p, over n.
Subtract p from r. Divide by the standard error of a rate with p and n. If z passes the tolerance, say 3, raise the alarm.
With a made-up batch: 137 nulls in n = 5,000, so r = 0.0274. The standard error is √(0.02 × 0.98 / 5,000) = 0.00198. z = 0.0074 / 0.00198 = 3.74, past 3: page.
The blue bell is the null count of healthy batches. The purple band is the tolerance. Orange is today's count. Then raise the number of checks and watch the noise pages add up.
Batch of 5,000 rows, baseline null rate 2%. False alarms assume healthy, independent checks with two-sided bands.
Each two-sided 3σ check fires on noise with chance 0.0027. Run 200 of them and you expect 200 × 0.0027 = 0.54 noise pages a day. Page at 4σ (chance 0.000063) and send 3σ hits to a daily digest: 200 checks then make one noise page every 79 days.
Run the same expectations in three places:
The failure. Symptom: on-call ignores data pages. Measure: noise pages per week, summed over all checks. Fix: tier the bands, give every check an owner, and give every skipped check an expiry date.
Chapter 6
Test the candidate on live traffic, size the canary, and write the rollback rule first
Offline gates miss four things. Only live traffic shows them:
Shadow mode sends a copy of live requests to the candidate and logs its answers without serving them. It shows crashes, latency under real load and the share of predictions that change. It cannot show user reactions. A canary serves the candidate to a small random slice of users, in stages such as 1%, 5%, 25%, 100%. Split by user, not by request, so one user's session stays in one arm.
How long must the canary run? Call the baseline conversion p1, the conversion after the drop you must catch p2, and their gap Δ.
n equals z-alpha plus z-beta, squared, times p-one q-one plus p-two q-two, over delta squared.
Add the two z values and square them. Multiply by the summed noise of the two arms. Divide by delta squared. Halve delta and n grows four times.
With made-up traffic: p1 = 0.080, p2 = 0.072, Δ = 0.008. n = 6.18 × 0.1404 / 0.000064 = 13,565 per arm. A 5% canary of 200,000 daily users gets 10,000 a day: 1.4 days.
The orange line is the measured canary minus control; the purple band is its 95% interval. On the decision day the canary rolls back if the whole band sits below zero. An error spike rolls it back at once. Make the canary small.
Illustrative: 200,000 users a day, baseline conversion 8%, a matched control slice the same size as the canary, baseline errors 10 per 10,000 requests.
Errors are fast. Expect 10 errors in the first 10,000 canary requests and see 50: z = (50 − 10) / √10 = 12.6. Roll back by rule, with no meeting. Write every rollback rule before the canary starts, so nobody argues during the incident.
The failure. Symptom: a config push takes down a fleet at once. In July 2024 a CrowdStrike content update passed a validator with a logic error and reached about 8.5 million Windows devices without staging. Measure: does every artifact go through stages? Fix: canary config and data like code.
Chapter 7
Read latency as a distribution, and see how fan-out turns a rare slow call into a common one
A model can be more accurate and still be a regression, because it answers in 900 ms instead of 40. Say 98% of requests take 40 ms and 2% take 900 ms. The mean is 57.2 ms, well under a 100 ms target. One user in fifty still waits almost a second.
A percentile is the value below which a given share of requests falls. The p99 is the latency that 99% of requests beat. Sort the sample; the nearest-rank p-th percentile is the value at position ⌈p/100 × n⌉.
Orange is the mean, teal the p50, p95 and p99, pink the target. Raise the slow share: the mean barely moves while p99 jumps. Then raise the fan-out.
Illustrative mixture: a fast hump near 40 ms and a slow hump at the chosen latency, on a log axis. Percentiles are exact for the mixture.
A request that fans out to k backends waits for the slowest. Call the chance that one backend is slow q.
P-slow equals one minus, one minus q, to the k.
One minus q is the chance one backend is fast. Raise it to the k: all k are fast. One minus that is the chance at least one is slow.
q = 0.01, k = 10: 0.9910 = 0.904, so Pslow = 0.096. A backend's p99 becomes the frontend's p90.
Take a made-up sample of 20 latencies from 12 to 120 ms. The nearest-rank p95 is the 19th value, 58 ms; the p99 is the 20th, 120 ms. NumPy's default interpolates and gives 61.1 ms and 108.2 ms. Pin the definition (method="inverted_cdf" is nearest rank).
Cost is the third budget. A prompt edit that raises answers from 180 to 240 tokens, at a made-up $15 per million output tokens and 2 million requests a day, adds $1,800 a day. Gate the output length too.
The failure. Symptom: the latency gate flips verdicts after a library upgrade. Measure: rerun the gate on stored latencies with both versions. Fix: pin the percentile method, the load profile and the hardware, and set the band from repeat runs.
Chapter 8
Treat the gate as a classifier over releases, and find the only move that improves both of its errors
Every release is truly good or truly regressed, and you cannot see which. The gate passes or blocks it. That is a 2 × 2 table, with "regressed" as the positive class.
| Gate blocks | Gate passes | |
|---|---|---|
| Truly regressed | true positive: a save | false negative: an incident |
| Truly good | false positive: lost time | true negative |
Gate recall is the share of regressions it blocks. Gate precision is the share of blocks that were right. Precision depends on how rare regressions are. Call the gate's detection rate r, its false-block rate f, and the share of releases that truly regress π.
Precision equals r pi, over r pi plus f times one minus pi.
r times pi is the share of releases that are correct blocks. f times one minus pi is the share that are wrong blocks. Precision is the correct blocks over all blocks.
With made-up rates r = 0.9, f = 0.10, π = 0.05: precision = 0.045 / (0.045 + 0.095) = 0.32. Two of every three blocks are wrong, from a good gate.
The gate sees a measured difference, not the truth. Good releases measure near 0; regressed ones near −2 points. Noise smears both into overlapping bells. A threshold on the overlap trades one error for the other. Only a smaller noise, a bigger golden set, pulls the bells apart.
Green bell: good releases. Red bell: regressed. Pink line: block below it. Press Run a quarter. Lower the base rate and watch precision fall; then raise n, not the strictness, to rescue it.
Illustrative: a regression is a true drop of 2 points; noise sd is 100 × √(0.065/n) points; an incident costs $100k and a wrong block $5k.
Take made-up gates, 100 releases and 20 regressions. Gate A catches 0.75 and false-blocks 0.10: 15 saves, 5 incidents and 8 wrong blocks; precision 0.65, cost $540k. Gate B catches 0.90 and false-blocks 0.25: 18 saves, 2 incidents, 20 wrong blocks; precision 0.47, cost $300k. At $20k per incident both cost $140k. The prices choose the threshold.
The failure. Symptom: many blocks and still some incidents. Measure: each quarter, count escapes from incident reviews and overturned blocks from retries. Fix: if both errors are high, cut noise (n, runs, soak time) before moving the threshold.
Chapter 9
Compute the escape rate of a stack, and see what shared blind spots do to it
A data regression must pass three layers to reach users. Validation misses it half the time, the offline gate a quarter of the time, the canary 30% of the time. If the misses are independent, multiply them:
Here each miss is the chance one layer lets the regression through. Of 100 regressions, 50 pass validation, 12.5 pass the gate and 3.75 reach users.
Each bar is how many of 100 regressions are still alive after a layer. Switch layers off. Then switch Correlated on: the canary now shares the gate's blind spots.
Illustrative miss rates 0.5, 0.25 and 0.30. Correlated sets the canary's miss to 0.60 for regressions the gate already missed.
Now say the canary watches the same metric as the gate on similar traffic. A regression the gate missed slips past the canary 60% of the time, not 30%. The escape becomes 0.5 × 0.25 × 0.60 = 0.075, twice as high, with the same boxes on the diagram.
| Level | What the team has |
|---|---|
| 0 | tests on code only |
| 1 | a golden set, compared by eye |
| 2 | paired gates with margins and measured run noise |
| 3 | data validation and drift monitors in production |
| 4 | canaries with pre-registered automatic rollback |
| 5 | the gate audited by its own precision and recall |
The failure. Symptom: incidents of one kind keep escaping a "five-layer" stack. Measure: for each regression class, list the layers that can see it. Fix: make each layer watch a different signal: inputs, distributions, offline quality, live behavior.
Chapter 10
Keep the terms, the numbers, the checks and the code in one place
Treat every noisy measurement as a distribution. Bound the downside, write the decision rule before you look, and audit the gate like any other classifier.
| Tool | Formula | Number from this page |
|---|---|---|
| Rate SE | √(p(1 − p)/n) | 0.0134 at p = 0.90, n = 500 |
| Paired gate | d = (c − b)/n, SE = √(b + c)/n | [−0.031, +0.001]: block at delta 0.01 |
| Golden-set size | (1.96 + 0.84)² pdis / δ² | 5,102 for a 1-point margin |
| Runs needed | (s / SE*)² | 8 runs for s = 0.0141, SE* = 0.005 |
| PSI | Σ (a − e) ln(a/e) | 0.050; the incident 0.73 |
| KS D | largest gap of the cumulative shares | 0.08 against 0.027 critical |
| Null-rate z | (r − p) / √(p(1 − p)/n) | 3.74; 0.54 noise pages a day at 200 checks |
| Canary n | (zα + zβ)²(p1q1 + p2q2)/Δ² | 13,565 per arm, 1.4 days at 5% |
| Fan-out | 1 − (1 − q)k | 0.096 at q = 0.01, k = 10 |
| Gate precision | rπ / (rπ + f(1 − π)) | 0.32 at π = 0.05 |
| Stack escape | product of misses, if independent | 3.75%; 7.5% when correlated |
pythonimport numpy as np from scipy.stats import norm def paired_gate(base_ok, cand_ok, delta=0.01, z=1.96): base_ok, cand_ok = np.asarray(base_ok, bool), np.asarray(cand_ok, bool) # shape (n,) n = base_ok.size b = np.sum(base_ok & ~cand_ok) # only the baseline is right c = np.sum(cand_ok & ~base_ok) # only the candidate is right d, se = (c - b) / n, np.sqrt(b + c) / n return d, (d - z * se, d + z * se), "BLOCK" if d - z * se < -delta else "PASS" def psi(e, a, eps=1e-6): e, a = np.clip(e, eps, None), np.clip(a, eps, None) terms = (a - e) * np.log(a / e) # rank these to find the bins that moved return terms.sum(), terms def null_rate_z(nulls, rows, p): return (nulls / rows - p) / np.sqrt(p * (1 - p) / rows) def canary_n(p1, p2, alpha=0.05, power=0.8): z = norm.ppf(1 - alpha) + norm.ppf(power) return int(np.ceil(z**2 * (p1*(1-p1) + p2*(1-p2)) / (p1 - p2)**2)) print(null_rate_z(137, 5000, 0.02)) # 3.74 print(canary_n(0.080, 0.072)) # 13565 print(1 - 0.99**10) # 0.0956 print(np.percentile([12,14,15,15,16,17,18,18,19,20,21,22,23,25,27,30,34,41,58,120], [95, 99], method="inverted_cdf")) # [58 120], nearest rank
| Wall you hit | What it looks like | Where to go |
|---|---|---|
| Too many checks | noise pages every day | multiple-testing corrections in eval statistics |
| Slow canaries | days to see a 10% drop | variance reduction in experiment design |
| A judge model drifts | scores move with no release | generative evaluation |
| Release plumbing | how to do blue/green and flags | Testing and Deployment |
AI Evaluation · CS 336: Evaluation · CS 329Z: Evaluation Fundamentals · Testing and Deployment
Sources for the real incidents: Anthropic, A postmortem of three recent issues (September 2025); Horace He and Thinking Machines Lab, Defeating Nondeterminism in LLM Inference (September 2025); CrowdStrike, Channel File 291 root cause analysis (August 2024); Microsoft, Helping our customers through the CrowdStrike outage (July 2024).
Now press Present or Teach and explain from memory: the paired gate, why the window comes from measured noise, what drift cannot see, and why precision falls when regressions are rare. Then go back to the hero and say why the null-rate check beats the labeled slice by a day.