Structured output
Constrain a model's response to a specific JSON shape with a StructuredOutputFormat on runInference.
When you need the model to respond with a specific JSON shape instead of free-form text, use structured output. Pass a structuredOutput (a StructuredOutputFormat) on the runInference params and the provider will enforce the JSON Schema.
import { runInference } from '@mozaik-ai/core';
runInference({
model: 'gpt-5.4',
context,
caller: this,
environment,
structuredOutput: {
name: 'weather',
schema: {
type: 'object',
properties: {
city: { type: 'string' },
temperature: { type: 'number' },
condition: { type: 'string' },
},
required: ['city', 'temperature', 'condition'],
additionalProperties: false,
},
strict: true,
},
});The response comes back as a ModelMessageItem with valid JSON in the text field — no new item type, consistent with OpenResponses.
Structured output works alongside tools and streaming. When streaming is enabled, partial JSON chunks arrive as SemanticEvents and the final event contains the complete response.
To return to free-form text, simply omit structuredOutput on the next runInference call.
Provider support
| Provider | Models | Strict schema enforcement |
|---|---|---|
| OpenAI | gpt-5.4, gpt-5.4-mini, gpt-5.4-nano, gpt-5.5 | Yes |
| Anthropic | claude-opus-4-7, claude-opus-4-8, claude-sonnet-4-6, claude-haiku-4-5 | Yes |
| Gemini | gemini-3.1-pro-preview, gemini-3.5-flash | Yes |
| DeepSeek | deepseek-v4-flash, deepseek-v4-pro | Not supported — use prompt-based JSON guidance instead |
Requesting structured output for a model whose specification has supportsStructuredOutput: false fails request validation before the API call.