Evaluating LLM Routing and Refusals: Confusion Matrix
On this page
Evaluating routing: answer, handoff or decline
Before DocsBot writes anything, it decides what to do with the message:
- answer from the docs,
- handoff to a human (legal threats, account-specific billing disputes, angry customers),
- decline politely (off-topic, such as "write my essay").
In error analysis on Day 3, "unneeded handoff" was a top failure mode. Unneeded handoffs cost support time. Missed handoffs are worse: a customer threatening legal action gets a cheerful docs link.
This is a classification problem, even when the model makes the choice implicitly inside a longer answer. Log the decision as a field, then grade it like a classifier.
Building a confusion matrix for routing
Run your tagged dataset, where each example has an expected route, and count every combination of expected and predicted route:
# routing_eval.py: confusion matrix and per-class precision/recall for routing decisions
from collections import Counter
LABELS = ["answer", "handoff", "decline"]
def confusion(pairs):
counts = Counter(pairs)
print(f"{'expected / predicted':<22}" + "".join(f"{l:>9}" for l in LABELS))
for exp in LABELS:
print(f"{exp:<22}" + "".join(f"{counts[(exp, pred)]:>9}" for pred in LABELS))
print()
for l in LABELS:
tp = counts[(l, l)]
predicted = sum(counts[(e, l)] for e in LABELS)
actual = sum(counts[(l, p)] for p in LABELS)
print(f"{l:<8} precision {tp / predicted:.2f} recall {tp / actual:.2f}")
pairs = ([("answer", "answer")] * 140 + [("answer", "handoff")] * 18 + [("answer", "decline")] * 2
+ [("handoff", "handoff")] * 25 + [("handoff", "answer")] * 5
+ [("decline", "decline")] * 8 + [("decline", "answer")] * 2)
confusion(pairs)expected / predicted answer handoff decline
answer 140 18 2
handoff 5 25 0
decline 2 0 8
answer precision 0.95 recall 0.88
handoff precision 0.58 recall 0.83
decline precision 0.80 recall 0.80Each row is what should have happened; each column is what did. The diagonal is correct. Off the diagonal you see the specific mix-ups: 18 answerable questions handed off, and 5 handoffs that DocsBot tried to answer.
Precision vs recall for handoffs
For handoffs:
- Precision 0.58: of all the handoffs DocsBot made, only 58 percent were needed. That's the support team's complaint.
- Recall 0.83: of the conversations that needed a human, DocsBot caught 83 percent. The other 17 percent are the dangerous ones.
Improving one usually costs the other. Telling the model to hand off less raises precision and lowers recall. Decide which error is worse for each class before tuning. For DocsBot, a missed legal threat is far worse than an unneeded handoff, so you'd set a recall target for handoffs, such as 0.95, and improve precision within it.
Over-refusal is a failure too
The same applies to declines. Teams focused on safety often measure only whether the bot declines bad requests. Then the bot starts declining good ones: "How do I delete a user?" gets refused because "delete" sounds risky. That's over-refusal, and users experience it as a broken product.
Keep both kinds of examples in the dataset: requests that must be declined and similar-sounding ones that must be answered. Measure recall and precision for the decline class together.
Slicing routing results by tag
Overall numbers average across very different situations. Slice the matrix by tag: handoff recall might be 0.98 for legal threats and 0.60 for frustrated customers. That tells you exactly which examples to add to the prompt or the classifier.
Check yourself
Handoff recall. Fewer handoffs will raise precision, but recall may drop, meaning customers who genuinely need a human don't get one. Watch recall on the handoff-needed examples alongside the overall handoff rate.
Not necessarily. Check decline precision and include benign look-alike requests in the dataset, such as legitimate account questions that resemble risky ones. Perfect recall can come with heavy over-refusal, which frustrates real users.
It makes the decision gradeable with exact match and a confusion matrix, instead of inferring it from free text with a judge.
For each true route, how often the bot chose each route. It shows not just accuracy but which mistakes happen, like answering when it should hand off.
A stable overall accuracy can hide a topic, like billing, where handoffs are badly missed. Slices reveal where to focus.