Make a model return data your code can parse every time — constrained decoding, a schema shaped for generation, and validation at the boundary. Use when parsing LLM output, extracting fields, or when JSON parsing fails intermittently.
--- name: get-structured-output category: ai-agents description: >- Make a model return data your code can parse every time — constrained decoding, a schema shaped for generation, and validation at the boundary. Use when parsing LLM output, extracting fields, or when JSON parsing fails intermittently. --- # Get Structured Output Asking for JSON in the prompt and calling `JSON.parse` works about 95% of the time, which is the worst possible number: too good to notice in testing, bad enough to page you weekly. Fix it in this order. ## 1. Use constrained decoding if you have it Most providers now support a JSON schema that constrains generation token-by-token — structured outputs, response format, tool/function calling. When available, this is the answer: the model is *unable* to emit a token that would break the schema, so parse failures stop entirely rather than becoming rare. Prompt-based JSON is a fallback for models that lack this, not a design choice.
You are reading the opening of this skill.
The rest is open to any signed-in account — free included. Reading the library costs nothing.
Shared publicly by the author and open for any use. See the Terms.