Asking for JSON
Explore how to request precisely shaped JSON objects from AI models by specifying field names, types, and allowed values. Understand why structured prompts improve reliability over vague prose requests and how this approach reduces code-breaking ambiguities, forming the foundation for parsing and validating AI responses in backend systems.
The previous lesson showed a response that was accurate but still broke our code because we never actually told the model what shape we needed. Asking more nicely in prose helps, but prose is still an open invitation to explain, hedge, or add context we didn't ask for. This lesson replaces vague requests with something far more specific: asking for JSON and describing exactly which fields it must contain, what type each one is, and which values are actually allowed.
From "give me a number" to "give me this exact object"
The severity-rating task from the last lesson is a good one to revisit because it's simple enough to see the improvement clearly. Instead of asking for a bare number, we can ask for a small JSON object with a defined shape, named fields, each with a defined type, and an explicit instruction to return nothing else. That's a genuinely different kind of request than anything in the previous lesson. We're not asking the model to answer a question in whatever form feels natural; we're handing it a contract and asking it to fill in the blanks.
The next example ...