What this does. Forces the model’s response to match a JSON Schema. The model cannot emit invalid JSON, missing fields, or extra keys. When to use it. Any downstream consumer that needs a known shape: database inserts, form-filling, tool arguments, data extraction, classification with fixed enums.Documentation Index
Fetch the complete documentation index at: https://runinfra.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
Minimal code
What to tune
| Parameter | Effect |
|---|---|
response_format: { type: "json_object" } | Looser mode. Any valid JSON, no schema enforcement. Use for free-form JSON |
response_format.json_schema.strict: true | Reject any response that doesn’t fit the schema (default for Pydantic / Zod helpers) |
temperature: 0 | Best for deterministic extractions; structured output handles non-zero too |
Common mistakes
- Using free-form prompts like “respond as JSON” without
response_format. The model can still emit trailing commentary or markdown fences. Always passresponse_format. - Schemas that allow
additionalProperties: true. Strict mode requiresadditionalProperties: false. The Pydantic / Zod helpers set this for you; raw JSON Schema users must add it. - Nested anyOf without discriminators. Use enums or discriminated unions; unbounded anyOf confuses the constrained decoder.
- Expecting enums to be case-insensitive. Schema enums are exact-match.
"Paris"won’t satisfyenum: ["paris", "berlin"].
Next steps
Tool calling
Structured args for tool invocations.
Streaming
Stream JSON that parses as it arrives.
RAG
Structured extraction over retrieved context.
API reference
Full
response_format contract.