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

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

This interactive level needs JavaScript. Built by (cybernerdie).