Defending AI Agents
עברית Join waitlist
Menu

Module 00 · Lesson 06

A 99%-recall detector's alerts can be wrong 99 times in 100: the base rate in depth

Lesson 5 stated the result: a detector with 99% recall and a 1% false-positive rate, run on traffic where 1 call in 10,000 is an attack, is right about 1 time in 100 when it fires. This lesson takes the result apart, because every threshold decision in Part III is this calculation with more care.

The calculation, and its inverse

Let \pi be the base rate (the fraction of calls that are attacks), TPR the detector's recall, FPR its false-positive rate. By Bayes:

\text{precision} = P(\text{attack} \mid \text{alert}) = \frac{\text{TPR}\,\pi}{\text{TPR}\,\pi + \text{FPR}\,(1-\pi)}

Hold TPR = 0.99 and \pi = 10^{-4} and move the FPR:

FPR Precision
10% 0.1%
1% 1.0%
0.1% 9.0%
0.01% 49.8%
0.001% 90.8%

Now run it backwards. Solve the formula for the FPR that gives a target precision P:

\text{FPR} = \frac{\text{TPR}\,\pi\,(1-P)}{P\,(1-\pi)}
Target precision FPR you need
50% 9.9 \times 10^{-5}
90% 1.1 \times 10^{-5}
99% 1.0 \times 10^{-6}

To have half the alerts be real you need a false-positive rate near one in ten thousand: 100 to 500 times below the 1% to 5% operating points of the detectors you build in Modules 4 and 7, and those are set on in-distribution data, which production is not (Module 8). The inverse is the useful direction: choose the precision your reviewers can live with, and the FPR budget follows.

Alerts are a staffing problem

At 50 million calls a day (2,000 agents at 25,000 calls each; this module's at-scale page) and \pi = 10^{-4} there are 5,000 attacks a day. At 2 minutes a review and 7.5 productive hours a day:

FPR Alerts a day Real among them Reviewers (full time)
1% 504,900 4,950 2,244
0.1% 54,945 4,950 244
0.01% 9,950 4,950 44

Nobody employs 2,244 reviewers for this, so alerts are sampled, queued until stale, or ignored, and the system's real recall drops to whatever fraction somebody looks at. A detector's effective recall is its recall multiplied by the fraction of its alerts anyone acts on. That is why the course keeps asking for an FPR budget tied to an action.

Why AUC does not warn you

ROC curves plot TPR against FPR; both are conditional on the class, so neither moves when \pi changes. Take two equal-variance Gaussian detectors, differing only in separation d', and measure each at FPR = 0.1%:

Separation AUC TPR at FPR 0.1% Precision at \pi = 10^{-4}
d' = 3 0.983 0.46 4.4%
d' = 4 0.998 0.82 7.6%

An AUC of 0.998 is headline-worthy and gives alerts that are wrong 92 times in 100. Report the operating point (TPR at the FPR your budget allows) and the precision at the deployment prior, never AUC alone. Precision-recall curves expose the problem because precision depends on \pi; they must be drawn at the deployment \pi, not the benchmark's.

The score is not a probability at deployment

Suppose a classifier trained on a balanced set (\pi_{\text{train}} = 0.5) outputs 0.99 for a call. Is that a 99% chance of attack? Only if deployment is also balanced. Adjusting for a new prior (Saerens, Latinne and Decaestecker, 2002) multiplies the odds by the ratio of prior odds:

\frac{p_{\text{new}}}{1-p_{\text{new}}} = \frac{p_{\text{old}}}{1-p_{\text{old}}} \cdot \frac{\pi_{\text{new}}/(1-\pi_{\text{new}})}{\pi_{\text{train}}/(1-\pi_{\text{train}})}

Here: 99 \times \frac{10^{-4}/0.9999}{1} \approx 0.0099, so p_{\text{new}} \approx 0.98\%. The score "0.99" means "about 1% likely" in production.

The adjustment rests on two assumptions, and both can fail: the score was calibrated at the training prior, and only the class prior changed between training and deployment, not what attacks and benign calls look like (label shift, not the covariate shift of Module 8).

The 0.98% matches lesson 5's precision, but it is a different quantity. Lesson 5's is an average over every alert: P(\text{attack} \mid \text{score above threshold}). This one is pointwise: P(\text{attack} \mid \text{score} = 0.99). They agree only because both likelihood ratios are 99: here the score's odds, 0.99/0.01; there \text{TPR}/\text{FPR} = 0.99/0.01. Change either and they part.

The prior is the soft spot

Everything above takes \pi as known. It is not. \pi is the rate of attacks in your traffic, which you cannot know without labelling traffic, and which an adversary can change. Treat it as a parameter with an interval, and report precision as a range. Two honest ways to bound \pi: (a) red-team rates times exposure (Module 9), and (b) a labelled random sample of production calls large enough to see at least a handful of attacks, which at \pi = 10^{-4} means labelling tens of thousands. The same holds for the FPR: it is estimated from a finite benign sample, and with zero false positives in n calls the one-sided 95% upper bound solves (1-p)^n = 0.05, so p = 1 - 0.05^{1/n} \approx \ln 20/n \approx 3/n, the rule of three (Module 1, lesson 9 uses it). Zero in 300 still allows 1%. Module 7 does the interval arithmetic.

One more asymmetry worth noticing: \pi is not exogenous. Raise detection and attackers move; lower friction and more of them try. The prior is a property of the whole system, including your defences.

Check yourself

  1. At \pi = 10^{-6} (one attack in a million calls), what FPR gives 50% precision at TPR 0.99? How many benign calls, with zero false positives among them, would the rule of three need before you could claim that FPR?
  2. Two detectors have the same AUC. Detector A has a higher TPR at FPR = 10^{-3}; B is better at FPR = 10^{-1}. Which would you deploy for a hold-for-review action at 500,000 calls a day with five reviewers? Show the arithmetic.
  3. A vendor reports "99.9% accuracy" on a balanced test set. State the two numbers you would ask for.
Answers
  1. \text{FPR} = 0.99 \times 10^{-6} \times 0.5/(0.5 \times (1 - 10^{-6})) = 9.9 \times 10^{-7}. Zero false positives in n calls certifies it once 1 - 0.05^{1/n} \le 9.9 \times 10^{-7}: about 3.03 million benign calls, the rule of three's 3/\text{FPR}.
  2. A. Five reviewers at 2 minutes a review and 7.5 hours a day clear 1,125 alerts, an FPR budget of 1{,}125/500{,}000 = 0.225\%. At \pi = 10^{-4}, FPR 10^{-3} gives about 500 false alerts plus at most 50 real ones, within budget; FPR 10^{-1} gives about 50,000, 44 times what the team can read. Only the region near 10^{-3} is usable, and there A is better.
  3. TPR and FPR separately, measured on traffic shaped like the deployment's. On a balanced set accuracy is (\text{TPR} + 1 - \text{FPR})/2, so 99.9% allows an FPR of up to 0.2%, which at \pi = 10^{-4} gives a precision of only 4.8% even with perfect recall.