Structured Data
Send a JSON schema with response_format and the reply conforms to it, so your
code can parse the answer instead of pulling values back out of prose. On
/v1/responses the same schema goes in text.format, covered
below.
Quick start with the OpenAI SDK
With the OpenAI SDK, response_format takes the schema directly:
cURL
Python
If you already use LangChain, with_structured_output takes a Pydantic model
and returns a typed object, which is often cleaner than handling
response_format yourself. See Using ASI:One with
LangChain.
Complex schema example
Nested objects and arrays work the same way, and additionalProperties: false
applies to every object in the schema rather than only the outermost one:
Best practices
Schema design
Use strict: true so the model follows your schema exactly rather than treating
it as a strong suggestion. Two things are required alongside it:
additionalPropertiesmust befalseon every object in the schema.- Every key in
propertiesmust be listed inrequired. To make a field optional, keep it inrequiredand add"null"to its type.
The same rules apply to tool schemas. See Strict mode for a worked example.
Beyond that:
Validation
Always validate and sanitize structured output before using it in production. A schema constrains the shape of the reply, not the truth of its contents.
On the Responses API
Everything above uses response_format on /v1/chat/completions. On
/v1/responses the equivalent is text.format, which takes the same JSON schema
in a flat shape rather than nesting it under json_schema:
cURL
Python
Both reuse the client built in the quick start above, and name is required
on text.format. The schema itself, including strict and
additionalProperties, is identical to the Chat Completions version, so you can
reuse it as-is.
Next steps
- Tool Calling - Let the model call your own functions
- Responses API - Where
text.formatapplies, and the rest of that endpoint - Using ASI:One with LangChain -
with_structured_outputinstead of raw JSON schemas - OpenAI Compatibility - Which parameters apply on which endpoint