Snippet · Building with models
Get JSON back reliably
Parsing prose is a losing game.
I need this model call to return data I can use directly, not prose: <describe what you're extracting> - Define the exact schema, with every field's type and whether it's required. - Use the API's structured output / tool-use mode if it has one, rather than asking politely for JSON in the prompt. Tell me which my provider supports. - Every field needs a defined "unknown" value. The model must be able to say it doesn't know, rather than inventing something. - Validate the response against the schema before using it, and say what happens when validation fails — retry, or fail loudly? Show me the schema, the call, and the validation.
Never parse JSON out of a prose response with a regex. Providers have a mode that guarantees the shape; use it, and the whole class of parsing bugs disappears.