Search⌘ K
AI Features

Asking for JSON

Explore how to design precise prompts that ask AI models for structured JSON output, defining exact fields, types, and allowed values. Understand the benefits and limits of this approach in creating more reliable AI responses for backend integration.

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 ...