Structured Outputs and Tool Compatibility
Explore how to enforce strict JSON schema outputs in AI models and use tool calling to interact with external systems. Understand how OpenRouter standardizes these features across providers and how plugins can extend model capabilities for robust, production-ready 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}}}}
Notice the settings: strict: true and additionalProperties: false. These ensure the model must adhere to the schema and cannot invent new fields. ... ...