response_format to your deployment so the serving engine constrains the response toward a JSON Schema. RunInfra forwards response_format to the model unchanged. The constraint is applied by the upstream serving engine (for example vLLM guided decoding), not by RunInfra.
When to use it. Any downstream consumer that needs a known shape: database inserts, form-filling, tool arguments, data extraction, classification with fixed enums.
Prerequisite: the deployment must support
response_format. RunInfra is a passthrough for this field, so JSON-schema enforcement depends on the serving engine and model behind your deployment. Most LLM deployments served by vLLM support guided JSON decoding. If your deployment does not, the model may return a normal completion that the SDK parse() helpers cannot parse, and you should fall back to the raw response_format request below plus your own JSON parsing. Test against your specific model before relying on strict enforcement.Minimal code
The SDKparse() helpers (Python client.beta.chat.completions.parse, TypeScript client.chat.completions.parse) wrap the raw response_format request and validate the result against your Pydantic or Zod model. They are convenient but depend on the deployment honoring the schema. The curl tab shows the raw response_format request, which is the portable form that works with any client and any deployment that supports JSON-schema decoding.
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 | Asks the serving engine to reject any response that does not fit the schema (set by the Pydantic / Zod helpers). Honored only if the deployment supports strict JSON-schema decoding |
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.