AISim › Chapter 3: Keeping it running
It broke the parser
Level 14. One in nine responses crashes your code.
Your invoice-extraction API asks the model to return JSON (vendor, date, line items), and your code parses it. It works in the demo. In production, every so often the model adds a friendly sentence, forgets a bracket or invents a field, and your parser throws. The customer sees a 500 error.
Goals
- error rate at most 1%
- accuracy at least 80%
- cost per 1,000 requests at most $3
Concepts: Structured outputs, JSON mode, Validation.
Hint
Look at what failed in the request inspector. Is the model wrong, or just badly formatted? There's a model setting built for exactly this. A validator helps too, but is it enough on its own?
What you learn
Asking nicely for JSON isn't a contract. Models occasionally break format, and at scale "occasionally" means constant crashes. Structured output (JSON mode or schema-constrained decoding) makes the model produce valid output by construction. A validator that checks and retries is the safety net, not the fix.
More in this chapter
- The provider is down (Level 11)
- The research assistant (Level 12)
- Think harder? (Level 13)
- Yesterday's answers (Level 15)
- The 9am board report (Chapter 3 boss)
This interactive level needs JavaScript. Built by Joshua Paul (cybernerdie).