Output Format Engineering: Schemas, Length Control, and Reliability, Part 2
Replace 'please return JSON' instructions with structured-output features so downstream code never has to parse around model whims.
40 min · Reviewed 2026
The premise
Asking the model nicely for JSON works most of the time and fails at 3am; structured-output schemas turn format from a wish into a contract enforced by the API.
What AI does well here
Define a JSON schema for the expected output
Use the provider's structured-output mode (function/tool calling)
Validate on receipt and retry with the validation error
Version the schema as the prompt evolves
What AI cannot do
Guarantee semantic correctness of fields
Replace business validation (e.g., 'this email exists')
Eliminate the need for a post-receipt sanity check
AI and output format contracts
The premise
Free-form output is fragile downstream. A clear schema, ideally enforced by the API's structured output mode, prevents most parsing bugs.
What AI does well here
Convert prose instructions into a JSON schema.
Suggest field types and enums.
Add a 'reason' or 'confidence' field where useful.
What AI cannot do
Stop the model from filling fields with junk.
Validate semantic correctness.
Replace runtime schema validation.
The Spec Pattern: Tell the AI What 'Done' Means
The premise
Most bad outputs come from missing success criteria, not weak models. State what 'done' looks like before asking for anything.
What AI does well here
Hit a clearly stated format and length budget.
Self-check against criteria you spelled out.
What AI cannot do
Infer your unstated quality bar.
Decide which trade-offs you prefer.
Format Contracts: JSON Schemas in the Prompt
The premise
Free-form text is hard to consume downstream; a schema in the prompt plus a validator on the output makes integration tractable.
What AI does well here
Match a schema you state explicitly.
Repair an output when given the validator error.
What AI cannot do
Always emit valid JSON without validation.
Invent the right schema for your downstream system.
Stripping Hedge Words From Model Output
The premise
Default model output is full of 'it depends' and 'generally speaking'. You can instruct it to commit, with a separate channel for genuine uncertainty.
What AI does well here
Drop filler hedges when told to.
Mark genuine uncertainty in a structured field instead.
What AI cannot do
Be more certain than its training warrants.
Tell you when its commitment is wrong.
Setting Length Budgets That the Model Actually Hits
The premise
Models are mediocre at exact word counts but good at structural budgets. Specify both the structure and an approximate length.
What AI does well here
Hit structural targets like '5 bullets, each <= 12 words'.
Approximate paragraph counts and section headings.
What AI cannot do
Hit an exact word count reliably.
Self-trim when the content does not fit.
Scaffolded Reasoning: Give the AI a Worked Solution Skeleton
The premise
Models reason better when the reasoning shape is pre-built. A skeleton with labeled slots forces complete coverage.
What AI does well here
Fill named slots in a template you supply.
Stay within sections you've defined.
Maintain consistent formatting across many outputs.
Avoid skipping sections when each is required.
What AI cannot do
Invent a useful structure when your skeleton is wrong.
Push back on a flawed template even when it produces nonsense.
Format Locking: Pin AI Output Shape with JSON Schemas
The premise
'Return JSON' is fragile; pasting an actual schema with required fields and types is reliable.
What AI does well here
Match a JSON schema you provide closely.
Include all required fields when schema lists them.
Use enums you define rather than free strings.
Stay within types you specified.
What AI cannot do
Validate JSON itself — invalid output still happens.
Guarantee schema compliance without a programmatic validator.
AI Output Format Control: JSON, Schemas, and Structured Generation
The premise
AI structured output reliability comes from a stack: schema declaration, format examples, constrained decoding when available, and validation with retry on failure.
What AI does well here
Producing valid JSON when given a clear schema
Following format examples shown in the prompt
Honoring constrained-decoding grammars at runtime
Self-correcting when shown a validation error
What AI cannot do
Guarantee schema conformance without constrained decoding
Invent reasonable values for required fields with no signal