A JSON Schema enum makes every label legal and no label impossible. Measured locally: every off-topic message was routed until an abstain value was added.
A schema cannot say no
Structured outputs are one of the most useful reliability tools for model-backed services. On a serving stack that supports schema-constrained decoding, you give the model a supported JSON Schema and the decoder restricts token choices accordingly. A completed constrained response can satisfy that schema; truncation, refusal and transport errors still need separate handling. For classification this looks perfect: declare "label": {"enum": [...]} and the model can only return one of your labels.
That guarantee has a cost that is easy to miss. The mask makes every label legal and everything else impossible, including "none of these". When a message does not belong to any category, the model still has to pick one, and the parser will happily accept it. A routing service built this way never reports "I do not know". It reports a confident-looking label for every input, including input it has never seen the like of.
The running example is the help desk at Belgavi's Book Store. Messages are routed to four queues: return requests, order status, gift cards and damaged items. Customers also write about job openings, author readings, account deletion and newsletter settings, none of which belongs to the four queues. Hansini owns the router and wants to know what happens to those messages.
Measured: what a constrained small model does with off-topic messages
The companion example enum_abstain_probe sends 12 in-domain and 12 off-topic synthetic messages to two local models through Ollama 0.40.18, with the format field set to a JSON Schema whose label is an enum, temperature 0 and a fixed seed. No hosted provider was called. Small local models were used because they run offline; larger models will score differently, and the point is the method, not the scores.
| Model and label list | In-domain correct (of 12) | Off-topic forced into a queue (of 12) | Off-topic abstained (of 12) |
|---|---|---|---|
| qwen2.5 0.5b, four labels | 3 | 12 | 0 |
| qwen2.5 0.5b, four labels plus none_of_these | 3 | 12 | 0 |
| qwen2.5 1.5b, four labels | 9 | 12 | 0 |
| qwen2.5 1.5b, none_of_these listed last | 8 | 8 | 4 |
| qwen2.5 1.5b, labels reversed, none_of_these last | 6 | 7 | 5 |
| qwen2.5 1.5b, none_of_these listed first | 10 | 6 | 6 |
Without an abstain value, every off-topic message was routed to a queue: 12 of 12 for both models. The 0.5b model put all 24 messages, in-domain and off-topic, into return_request, the first label in the list. The 1.5b model also sent every off-topic message to return_request, and labelled all three order-status messages as returns. Adding none_of_these changed nothing for the 0.5b model. For the 1.5b model it caught 4 to 6 of the 12 off-topic messages depending on where the value sat in the list, and in-domain accuracy moved between 6 and 10 of 12 with the order alone.
Three conclusions follow, and none of them depends on the model being small. A closed enum turns "no fitting label" into a silent misroute. An abstain value is necessary but not sufficient. And label order is a variable you must hold fixed and measure, not a cosmetic choice.
Why the mask forces an answer
Constrained decoding works token by token. At each step the serving stack computes which next tokens keep the output a valid prefix of the schema, and sets the probability of every other token to zero before sampling. Once the model has written {"label": ", the only valid continuations are prefixes of the enum strings. If the model's own preference was to write something else, that probability mass is redistributed over the allowed labels. With temperature 0, the most likely allowed prefix wins. A shared prefix or the first-listed value can win for reasons that have nothing to do with the message.
Design the schema so abstaining is a real option
Give the model a legal way out, and describe it.
{
"type": "object",
"properties": {
"label": {
"type": "string",
"enum": ["none_of_these", "return_request", "order_status", "gift_card", "damaged_item"]
},
"reason": {"type": "string", "maxLength": 200}
},
"required": ["label", "reason"]
}In the prompt, say what none_of_these means and give one or two examples of messages that belong there. Put the definitions in the prompt, not only in label names. A short reason field placed after the label does not change what the label was conditioned on, so do not rely on it to improve the label. If you want evidence before the label, explicitly request a short evidence field and verify the actual generation order. JSON object property order is not a semantic guarantee. Measure whether the change helps rather than assuming it does.
Do not trust the abstain value alone
Even in the best row above, half the off-topic messages were still routed into a queue. Add a separate check for the cases that matter. Another prompt to the same model can make correlated mistakes, so it is not statistically independent evidence.
- An explicit relevance step. Ask a separate yes-or-no question first: does this message concern returns, order status, gift cards or damaged items? Constrain that answer too, and only classify when it says yes.
- Score margins where available. Some serving stacks return token log probabilities. A small score gap may justify review, but multi-token labels need comparable whole-label scores. Raw next-token probabilities and self-reported confidence are not calibrated label probabilities; the 0.15 threshold below is illustrative and needs evaluation.
- Queue-side validation. Each queue can check the minimum it needs, such as an order number for order status, and bounce messages that lack it.
- A default human queue.
none_of_these, low margins and bounced messages all go to a person, and that queue's volume is a metric.
def route(message: str, classify, relevant) -> str:
if not relevant(message): # constrained yes/no
return "human_review"
label, margin = classify(message) # constrained enum including none_of_these
if label == "none_of_these" or margin < 0.15:
return "human_review"
return labelFailure modes in production
A new topic appears. A store starts selling gift wrapping and customers ask about it. A closed enum routes those messages into an existing queue, and nothing errors. Track the share of messages per label over time. A sudden rise in one queue is often a new topic being forced into it.
Label order changes in a refactor. Someone sorts the enum alphabetically and accuracy moves by several points with no prompt change. Pin the order in code and include it in evaluation reports.
Evaluating on in-domain data only. An evaluation set drawn from the four queues will never show the forcing problem. Keep a fixed off-topic set and report "forced into a queue" as a first-class number next to accuracy.
Overcorrecting. A prompt that pushes hard toward abstaining can send in-domain messages to the human queue. Report both numbers together.
Choosing the abstain wording
The name and definition of the abstain value matter more than they look. A label such as other invites the model to use it for in-domain messages it finds hard, which lowers in-domain recall. A label that states the condition, such as none_of_these, with a one-line definition in the prompt ("the message is not about returns, order status, gift cards or damaged items") ties it to the category list. Test two or three wordings on the same fixed sets, keep the label order fixed while you do, and choose by the pair of numbers, forced and abstained, rather than by accuracy alone.
When you do not need this
If the input space is closed by construction, for example the label of a button a user pressed, a closed enum is fine. If every message already passed a deterministic filter that guarantees one of the categories applies, the abstain value adds nothing. The problem is specific to free text where the world can produce something your enum did not anticipate.
How to verify it
Build two fixed sets: in-domain messages with known labels and off-topic messages that belong to none. Run them through the exact schema, prompt, label order, model and settings you deploy, and report correct, abstained and forced counts for each set. Repeat whenever the model, the schema or the label order changes. The companion example does this for two local models and checks the counts above; replace its model list with yours. The measured numbers here are specific to those two small models and those 24 messages, and they are meant to show the shape of the result, not a ranking.