This client is made up. The clinics, the people and the 21 emails are invented. The numbers come from my own lab runs.
The client’s problem. A made-up group of four clinics sends IT requests by email, and a night script turns them into tickets.
The simple way. Version A says “reply in JSON” in the prompt, and code parses the text. I ran the 21 test emails 5 times each on Claude Haiku 5.5, so 105 calls. Only 82% of the replies had the right shape. Over the 105 calls, 28 wrong tickets reached the queue.
What broke. “Reply in JSON” does not mean JSON. The reply is just text, a string. Version B fixed the shape with a schema in the API. The shape was right in 100% of the replies. But 25 wrong tickets still reached the queue. The schema made the system more reliable. It also made it more dangerous, because people start to trust the script. It works, but that does not mean the priority is right. Before, if something did not work, it did not work. Now it can work and still be wrong.
The schema forces the shape, so urgency is always one of four words, but which word is still the model’s guess.
def schema(evidence: bool) -> dict:
"""The JSON schema the API enforces in arms B and C. Written by hand so it is easy to read."""
nullable = lambda t, **extra: {"anyOf": [{"type": t, **extra}, {"type": "null"}]}
props = {
"requester": nullable("string"),
"category": {"type": "string", "enum": ["hardware", "software", "network", "account", "other"]},
"urgency": {"type": "string", "enum": ["critical", "high", "normal", "low"]},
"due_date": nullable("string", format="date"),
"summary": {"type": "string"},
}
...
The fix. Version C adds checks in code, and a doubtful ticket goes to review. Then I made the prompt rules clearer. For example, critical now means people cannot do their work now. With these rules on Haiku (run 5), 7 wrong tickets reached the queue over 105 calls. But I wrote these rules after I saw the first runs, on the same 21 emails.
Code can catch some things, like an email that gives orders or a high urgency with no words behind it, but it cannot decide the urgency.
def check(ticket: dict, case: dict) -> list[str]:
"""Why a ticket must go to review instead of the queue. An empty list means it may go to the queue."""
text = email_text(case)
problems = []
if ticket["gives_orders"] or any(w in text.lower() for w in ORDER_WORDS):
problems.append("orders: the email tries to change the rules")
...
quote = ticket["urgency_quote"] or ""
shouting = any(ch.isalpha() for ch in quote) and quote == quote.upper()
if ticket["urgency"] in ("critical", "high") and (not quote or shouting):
problems.append("urgency: no evidence, or only shouting")
...
return problems
My prediction. Before the run I guessed 15, 10 and 0 wrong tickets. I did not say if that was per 21 emails or per 105 calls. Either way, my main guess was wrong: C was not 0.

Wrong tickets in the queue, 105 calls each
The details
Each morning the team goes through the queue and picks tickets by category and urgency. A ticket has a requester, a category, an urgency and a due date. “All four fields right” below means all four match my label for that ticket.
In version A, 18% of the replies gave no tickets at all. The 28 wrong tickets do not count those lost emails. All four fields were right in 57% of the 115 labelled tickets (21 emails, 23 requests, 5 times each). The lost replies count as wrong here. In version B it was 83%. In version B the urgency matched my label in 93% of the tickets.
One email says the badge reader at the staff entrance is broken, and people are waiting outside. My label is critical. In run 1, with the old rules, Haiku marked it high in all 5 repeats, in A, B and C. A missed critical is worse than a false one. Better to wake someone up.
In run 1, version C sent 6 tickets to review. All 6 were real mistakes, and there were no false alarms. The checks caught the email that tells the model to ignore its rules and mark the ticket critical. But 20 wrong tickets still passed every check and went to the queue. All four fields were right in 82% of the tickets, close to B. I ran C with the old rules again in run 3, and 24 wrong tickets reached the queue.
In run 5, with the clearer rules, all four fields were right in 90% of the tickets. The badge reader was critical in all 5 repeats. I also look at pass^5. An email passes when it is right in all 5 repeats. In A, 33% of the 21 emails passed. In run 5, 71% passed. The 7 wrong tickets in run 5 passed every check.
The new rules also say what “other” means: the cause is not known. I wrote these rules after I saw the earlier runs. I also changed some labels during the lab. All runs here are scored again with the final labels.
How others do it
The Claude API docs on structured outputs show what the schema guarantees and where it does not.
Good LLM Validation is Just Good Validation shows field validators in Pydantic, and asking the model again with the error message. In my lab a failed ticket goes to review instead.
Libraries like Instructor wrap this and add retries. I used the API’s own schema, to see each part myself.
What I learned
Code cannot decide urgency and category. That is a judgment.
In this lab, a bigger model did not help. With the same old prompt in version C, Haiku put 20 and 24 wrong tickets in the queue (two runs), and Claude Sonnet 5.5 put 35 (one run). I did not run Sonnet with the new rules. Sonnet cost $0.469 for the 105 calls, Haiku $0.038. Both models ran at effort medium. Sonnet’s default is high. The emails are short, so a small, cheap model reads them well. What matters is how clearly the prompt describes the rules. With the new rules, Haiku cost $0.041.
The labels changed during the lab. The first thought is not always right. You need time with the client to go through the edge cases and agree what each one means. The server room with no lights could be anything: power, a switch. The real question there is the urgency.
json.loads failed on some replies. A real night script would crash there. In a medical setting a loud failure is better than a quiet wrong ticket. But a real script should not crash at all. Anything doubtful should go to review, one email at a time, and the rest should go on.
For a new client I would start with a small model, clear rules and checks in code. With JSON output the AI becomes a function with known fields, so the code does not crash. If the code works but the meaning is wrong, that is work with the client on clearer rules.
Built with Claude Code.
How do you agree on the edge cases with a client before you trust a score like this?