Many LLM features have a third option besides "right" and "wrong": not answering. An invoice extractor sends a document to a human queue. A classifier falls back to a general inbox. A migration agent leaves a file alone and flags it. The trigger is usually picked by feel. Someone writes if confidence < 0.8: escalate, the number survives three model upgrades, and nobody can say what error rate it buys or how much work it creates for reviewers.
This article shows how to choose that threshold from data. You measure how error and coverage trade off for a confidence signal you can compute, then pick the point that meets an error budget written down in advance, with a margin for how little a few hundred labeled cases can actually prove.
Abstention is two numbers, not one
A feature that can abstain has two properties you need to track separately:
- Coverage: the fraction of inputs the system answers on its own.
- Selective risk: the error rate on the inputs it does answer.
Raising the threshold lowers coverage and, if the signal is any good, lowers risk. Plotting risk against coverage over every threshold gives a risk–coverage curve, a tool from the selective-classification literature (see Geifman and El-Yaniv, 2017) that carries straight over to LLM features.
Why two numbers instead of plain accuracy? Because the two failure modes cost different things and land on different people. A wrong automated answer costs the user. An abstention costs reviewer time, or the user's patience. Abstaining on 70% of inputs at 1% risk and abstaining on 5% at 12% risk are completely different products. Before looking at any curve, write down both constraints: the highest error rate you'll accept on automated answers, and the lowest coverage (or highest review volume) the feature can live with.
Choose a signal you can compute, then test whether it ranks
The curve only helps if the per-input score ranks well, meaning wrong answers tend to score lower than right ones. Common candidates:
- Agreement across samples. Sample the prompt N times at nonzero temperature and score each input by the share of samples matching the most common answer. This is the voting idea behind self-consistency (Wang et al.), used here as a score. It suits answers you can compare exactly (labels, numbers, IDs). It fails when the model is consistently wrong, because five identical wrong answers score as certain, and it multiplies cost by N.
- Self-reported confidence. It's cheap, but the values often bunch into a few round numbers and can move when the prompt or model changes. Measure it like any other candidate, and don't read it as a probability.
- Token log-probabilities, where exposed. These can be strong for single-token labels. For longer answers, combining them into one score (sum, mean, first token) is an arbitrary choice that needs testing.
- External checks. Do the line items add up to the extracted total? Does the generated SQL parse? Rule-based checks often rank best, because they fail independently of the model's own beliefs.
Signals can be combined, for example by scoring any failed rule-based check as zero and using agreement otherwise. Don't argue about which signal is "better". Compute each one's curve on the same labeled set. The one whose curve sits lower in the coverage range you care about wins.
Worked example: compute the curve and pick a threshold with a safety margin
You need a labeled set that mirrors production traffic: for each input, whether the system's answer was correct and its confidence score. Standard-library Python:
import math
def wilson_upper(errors, n, z=1.96):
"""Upper end of the Wilson score interval for an error rate."""
if n == 0:
return 1.0
p = errors / n
denom = 1 + z * z / n
center = p + z * z / (2 * n)
margin = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n))
return (center + margin) / denom
def risk_coverage(cases):
"""cases: list of (score, is_correct). Higher score = more confident."""
ranked = sorted(cases, key=lambda c: c[0], reverse=True)
rows, errors = [], 0
for i, (score, ok) in enumerate(ranked, start=1):
errors += 0 if ok else 1
# only emit a row where the score changes, so ties are accepted together
nxt = ranked[i][0] if i < len(ranked) else None
if nxt != score:
rows.append({
"threshold": score,
"accepted": i,
"coverage": i / len(ranked),
"risk": errors / i,
"risk_upper": wilson_upper(errors, i),
})
return rows
def pick_threshold(rows, max_risk):
"""Lowest threshold (most coverage) whose *upper bound* on risk is within budget."""
ok = [r for r in rows if r["risk_upper"] <= max_risk]
return min(ok, key=lambda r: r["threshold"]) if ok else NoneOutput for an illustrative synthetic set of 400 cases scored by 5-sample agreement (possible scores 0.4 to 1.0):
| threshold | accepted | coverage | observed risk | 95% upper bound | |---|---|---|---|---| | 1.0 | 192 | 48% | 2.1% | 5.2% | | 0.8 | 254 | 64% | 4.3% | 7.6% | | 0.6 | 331 | 83% | 8.2% | 11.6% | | 0.4 | 400 | 100% | 15.8% | 19.6% |
Three lessons from this table:
First, choose on the upper bound, not the observed rate. With a 5% error budget, the observed risk says "accept only unanimous answers, 48% coverage, 2.1% error: done." But 4 errors in 192 cases is also consistent with a true error rate a little above 5%, so pick_threshold(rows, 0.05) returns None. This set can't support that promise at any threshold. The honest options are to label more cases, loosen the budget, or improve the signal. With a 10% budget it returns 0.8: 64% coverage, with an upper bound of 7.6%. Wilson is used because it stays sensible for small counts and rates near zero, where the normal approximation breaks down. For scale: 1 error in 40 cases looks like 2.5% but has a 95% upper bound near 13%, and even 0 errors in 40 cases only bounds the rate at about 9%.
Second, ties are accepted together. You can't accept "half of the 0.8s", so a signal with five distinct values gives you only five operating points. If none of them fits, try a finer-grained signal rather than inventing a fractional threshold.
Third, picking and measuring on the same data is optimistic. Scanning many thresholds and keeping the best overfits, which is why Geifman and El-Yaniv correct their bound for the number of thresholds tried. The practical fix: choose on one split and report coverage and risk on a held-out split. If held-out risk exceeds the budget, the threshold wasn't supported.
Where this breaks: noisy labels make every risk number noisy, so spot-check high-confidence "errors" first, because they are often answer-key mistakes. And if correctness isn't binary, as with summaries, you need a rubric-based pass/fail label before any of this applies.
Running the threshold in production
A threshold is a claim about one model, prompt, signal and traffic mix:
- Store the threshold with its evidence: dataset version, curve, chosen point and budget. "Why 0.8?" should be answered by a file, not a memory.
- Re-fit on every model or prompt change. A more accurate model can still shift the score distribution, and self-reported confidence is especially prone to this. Your eval run should produce a new curve, not just a new accuracy number.
- Watch coverage as a leading indicator. Production coverage is visible immediately, but production risk only shows up once labels or complaints arrive. A sudden change in the abstain rate, in either direction, means the inputs or scores moved and the guarantee no longer holds.
- Check slices. A global threshold can meet the budget overall while one language or document type runs far above it. Per-slice thresholds need enough labeled cases in each slice to support their own bound. Often it's better to abstain on the whole weak slice until you have that data.
- Recycle abstentions. Reviewed abstentions are labeled, hard, real cases. Add a sample of them to the next calibration set, along with a random sample of confident answers, so the set stays representative.
Checklist
- [ ] Write down the error budget for automated answers and the minimum acceptable coverage, before looking at data.
- [ ] Build a labeled set that mirrors production traffic; audit high-confidence "errors".
- [ ] Compute a risk–coverage curve for each candidate signal on the same set, and keep the one that ranks best where you plan to operate.
- [ ] Choose the threshold using an upper confidence bound on risk, not the observed rate. If nothing qualifies, get more data or change the budget.
- [ ] Confirm the chosen threshold on a held-out split you didn't use to pick it.
- [ ] Version the threshold with its dataset, curve and budget. Re-fit after any model, prompt or signal change.
- [ ] Alert on shifts in production coverage, check key slices, and recycle reviewed abstentions into the next calibration set.
Further reading
- Geifman & El-Yaniv, Selective Classification for Deep Neural Networks (NeurIPS 2017): risk–coverage curves and choosing a rejection threshold with a guaranteed risk bound.
- Geifman & El-Yaniv, SelectiveNet: A Deep Neural Network with an Integrated Reject Option (ICML 2019): learning the reject option instead of thresholding afterward.
- Wang et al., Self-Consistency Improves Chain of Thought Reasoning in Language Models: the sampling-and-voting idea behind agreement scores.
- Binomial proportion confidence interval: Wilson score interval: the formula used in
wilson_upper.
Comments (0)
No comments yet — be the first.
Sign in to leave a comment.