Structured output
Constrain a model's response to a JSON shape with structuredOutput on InferenceInput.
When you need the model to respond with a specific JSON shape instead of free-form text, pass structuredOutput on the InferenceInput you give runLoop. The provider enforces the JSON Schema.
runLoop(agent.getId(), message, {
model: 'gpt-5.4',
context: agent.getMemory().getContext(),
structuredOutput: {
name: 'weather',
schema: {
type: 'object',
properties: {
city: { type: 'string' },
temperature: { type: 'number' },
condition: { type: 'string' },
},
required: ['city', 'temperature', 'condition'],
additionalProperties: false,
},
strict: true,
},
});StructuredOutputFormat is { name?: string; schema: Record<string, any>; strict?: boolean }.
The response comes back as a ModelMessageItem with valid JSON in the text field — no new item type. You read it from model.answer ({ answer: ModelMessageItem }) or from inference.completed.
Structured output works alongside tools and streaming. To return to free-form text, omit structuredOutput on the next runLoop.
Provider support
Requesting structured output for a model whose specification has supportsStructuredOutput: false fails validation before the API call.
| 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 — supportsStructuredOutput is false |