WithResponseFormat to request structured output — for example JSON with a schema the model must follow.
Default (text)
OmitWithResponseFormat — the LLM responds as plain text:
JSON with schema
Useinterfaces.ResponseFormatJSON with a valid JSON Schema. The root must be type: "object" with properties:
result.Content as JSON in your application.
The schema root must be
type: "object". Primitive or array roots are not valid JSON Schema for Structured Outputs.Provider support
Structured Outputs (JSON schema enforcement) require models that support it — for examplegpt-4o and gpt-4o-mini on OpenAI. Older models may fall back to JSON mode without strict schema enforcement.
Example
JSON Response
Structured output with response format
Related
LLM Providers
OpenAI, Anthropic, and Gemini clients
Reasoning
Extended thinking alongside structured output
Configuration
WithResponseFormat reference
Tools
Combine structured output with tool use