Search⌘ K
AI Features

Structured Outputs and Tool Compatibility

Understand how to enforce strict JSON schemas for predictable AI model outputs and enable tool calling for models to interact with external systems. Learn to handle model-specific differences and extend capabilities with plugins like response healing and web search to build robust, data-driven AI applications.

Text is a poor format for software. If you are building a system that needs to extract user data, update a database, or trigger an external API, you need predictable, machine-readable output. You need JSON. This lesson covers how to force models to produce reliable structured data, how to enable tool calling so models can interact with external systems, and how OpenRouter standardizes these capabilities across a fragmented ecosystem.

Asking a model to output JSON through prompting alone is unreliable. Models may wrap the JSON in Markdown backticks, hallucinate extra fields, omit required ones, include conversational filler like “Here is your JSON:”, or produce malformed syntax.

If your application code tries to parse that response directly, it will crash.

Enforcing structure

Modern models support structured outputs: instead of asking for JSON in your prompt, you provide a strict blueprint (a JSON Schema) that the model must follow.

OpenRouter standardizes this capability via the response_format parameter in your request body.

Here is an example of how to force a model to extract a user’s name and age:

{
"model": "openai/gpt-5.4",
"messages": [
{ "role": "user", "content": "Extract info: John Doe is 32 years old." }
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "user_extraction",
"strict": true,
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name", "age"],
"additionalProperties": false
}
}
}
}
Using response_format with a sample request

Notice the settings: strict: true and additionalProperties: false. These ensure the model must adhere to the schema and cannot invent new fields. ... ...