Sub topic 7
Using Confidence and Abstaining When Unsure
This chapter assumes you can call a chat API from Python, read JSON, and know what accuracy, precision, and recall mean. It also assumes you have a classifier that returns a validated label and a confidence value, as built in the previous chapters.
Why a classifier should be allowed to say "I don't know"
A classifier that must always commit will sometimes be wrong. In a routing system, a wrong label sends a message to the wrong team, and nobody notices until a customer waits. Abstaining means the classifier declines to decide and hands the item to a person. It trades some automation for fewer silent mistakes.
There are two ways a message ends up in the abstain path:
- The model says it is unsure, through a low confidence value.
- The model picks the fallback label
other, which means no defined label fits.
Both lead to the same place: a human-triage queue.
Where the confidence number comes from
In our prompt, the model replies with {"label": "...", "confidence": 0.0-1.0}. This number is self-reported. The model writes it as text, like the label. It is not a probability computed from the model's internals.
That has consequences:
- Models tend to be overconfident. Values such as 0.9 and 0.95 appear often, even on wrong answers.
- The values are not calibrated. A reported 0.8 does not mean the label is right 80% of the time.
- Different prompts and models produce different scales.
So treat confidence as a ranking signal, not a probability. Higher values are usually more reliable than lower ones, but you must check this against your own labeled data.
Applying a threshold
The route function from the routing chapter uses a threshold. Any result below it goes to a person.
QUEUES = {
"billing": "billing-team",
"technical": "support-engineering",
"account": "account-services",
}
def route(text, call_llm, threshold=0.7):
label, confidence = classify(text, call_llm)
if confidence < threshold:
return "human-triage"
return QUEUES.get(label, "human-triage")The classify function returns ("other", 0.0) when parsing fails twice. Because 0.0 is below any sensible threshold, a malformed reply also lands in human triage. The same line covers two cases: the model was unsure, and the model's output was unusable.
Note that QUEUES.get(label, "human-triage") handles other even when its confidence is high. A confident "nothing fits" still needs a human.
Choosing a threshold from data
Do not pick 0.7 by feel. Run your labeled set through the classifier, record the confidence for each prediction, and see how accuracy changes as you raise the cutoff.
def threshold_report(results, thresholds):
# results: list of (predicted, expected, confidence)
rows = []
for t in thresholds:
kept = [r for r in results if r[2] >= t]
accuracy = (
sum(1 for p, e, _ in kept if p == e) / len(kept) if kept else None
)
coverage = len(kept) / len(results)
rows.append((t, coverage, accuracy))
return rowsCoverage is the share of items the system handles automatically. Accuracy is measured only on those items. Raising the threshold usually increases accuracy and lowers coverage.
| Threshold | Coverage (automated) | Accuracy on automated items |
|---|---|---|
| 0.5 | 96% | 88% |
| 0.7 | 85% | 93% |
| 0.9 | 55% | 97% |
The numbers above are illustrative. Your table will differ. Pick the row that matches your cost of a wrong route compared with your cost of a human review.
Common errors
- Trusting the number blindly. A single threshold chosen without data can send wrong items through at 0.95.
- Measuring accuracy on all items only. Overall accuracy hides the benefit of abstaining. Report coverage next to it.
- Forgetting the human queue's capacity. If 40% of items abstain and the team can handle 10%, the queue becomes the bottleneck.
- One threshold for every label. A billing mistake may cost more than a technical one. Per-label thresholds are possible once you have enough data for each label.
Exercise
Your labeled set gives 93% accuracy at a threshold of 0.7 with 85% coverage, and 97% accuracy at 0.9 with 55% coverage. Your human team can only review 20% of messages. Which threshold fits, and why?
Show answer
The 0.7 threshold. At 0.9, 45% of messages go to humans, which is more than double the team's 20% capacity. At 0.7, 15% go to humans, which fits. The accuracy gain from 0.9 is not usable if the review queue overflows.