Your LLM classifier is guessing and not telling you: use logprobs to route the uncertain cases
Monday AI Insight. One practical lesson for anyone using an LLM as a classifier: the label text says nothing about how sure the model was. "Politics" at 100% and "Politics" on a coin flip look identical in message.content . Ask for logprobs, and you can tell them apart. The problem: every answer lo

Monday AI Insight. One practical lesson for anyone using an LLM as a classifier: the label text says nothing about how sure the model was. "Politics" at 100% and "Politics" on a coin flip look identical in message.content. Ask for logprobs, and you can tell them apart.
LLMs are now the default classifier for a lot of glue work: ticket routing, intent detection, content tagging, "is this answer supported by the context, true or false?" The usual call returns one word and you act on it.
But some inputs are easy and some are genuinely ambiguous. Without a confidence signal you treat both the same way, so the ambiguous ones get auto-processed right alongside the obvious ones. You only find the errors later.
In the OpenAI Chat Completions API you can set:
A logprob is log(p). It is 0.0 at 100% probability and negative otherwise, so exp(logprob) turns it back into a probability. If a token is outside the top 20, the API uses -9999.0 to signal "very unlikely".
The OpenAI Cookbook's Using logprobs notebook shows exactly why this matters. It classifies news headlines into Technology, Politics, Sports or Art with top_logprobs=2:
Same one-word output format for all three. Only the logprobs show the third one was a mixed case. The Cookbook's suggestion: auto-classify above a threshold and send less certain ones to manual review.
import math from openai import OpenAI client = OpenAI ( ) LABELS = [ "billing", "bug", "feature", "other" ] # short, distinct labels PROMPT = """Classify the support ticket into exactly one label: billing, bug, feature, other. Reply with the label only, lowercase, nothing else. Ticket: {ticket}""" def classify ( ticket: str, model: str ): resp = client. chat. completions. create ( model = model, # must be a model that returns logprobs messages = [ { "role": "user", "content": PROMPT. format ( ticket = ticket ) } ], temperature = 0, max_completion_tokens = 1, # we only need the label's first token logprobs = True, top_logprobs = 10, # up to 20 ) first = resp. choices [ 0 ]. logprobs. content [ 0 ] # Sum probability per label; several tokens can map to one label # (e.g. "Bug", "bug", " bug"), and some tokens map to no label at all. scores = { label: 0.0 for label in LABELS } for alt in first. top_logprobs: tok = alt. token. strip ( ). lower ( ) for label in LABELS: if tok and label. startswith ( tok ): scores [ label ] += math. exp ( alt. logprob ) label = max ( scores, key = scores. get ) return label, scores [ label ], scores def route ( ticket: str, model: str, threshold: float = 0.90 ): label, p, _ = classify ( ticket, model ) if p >= threshold: return { "label": label, "p": p, "action": "auto" } return { "label": label, "p": p, "action": "review" } # human or a stronger model Enter fullscreen mode Exit fullscreen mode A few details matter here:
A probability from the model is not automatically a calibrated probability: "90%" should mean right about 90% of the time, and nothing guarantees that.
So the format advice above isn't just tidiness. It's the setting where these probabilities are most likely to mean something. Then check it on your own data:
Takeaway: a label alone doesn't tell you how sure the model was. Its first token's probability does, if you ask for it and check it against labeled data.
What do you route your low-confidence LLM outputs to today: a human, a bigger model, or nothing?