Improving Structured Outputs in the Gemini API
Today, we're announcing enhancements to Structured Outputs in the Gemini API, with expanded support for JSON Schema and better adherence to property ordering in the output.
Structured Outputs enable AI models to generate responses that guarantee adherence to a specific schema, which is important for tasks like data extraction and database population. They are also important for agent communication: one agent’s output becomes another’s formatted input, enabling complex multi-agent systems to collaborate without translation layers.
Expanded JSON Schema support
We’ve now added support for JSON Schema to all actively supported Gemini models. This enables libraries like Pydantic (Python) or Zod (JavaScript/TypeScript) to work out-of-the-box with the Gemini API. It builds upon the current support for the Gemini API’s Schema object that is based on OpenAPI 3.0 for Structured Outputs and Function Calling.
This update also adds support for frequently requested JSON Schema keywords, including:
- anyOf for conditional structures (Unions)
- $ref for recursive schemas
- minimum and maximum for numeric constraints
- additionalProperties and type: 'null'
- prefixItems for tuple-like arrays
Implicit property ordering
One of the important updates we have made is that the API now preserves the same order as the ordering of keys in the schema. This is supported for all Gemini 2.5 models and beyond and also applies to our OpenAI compatibility API. You can see this in action in this content moderation example using Pydantic:
Structured Outputs in the real world
Structured Outputs is one of the most frequently used tools by developers building real-world AI applications. Here are some examples of how some of our early access partners have used the tool to improve their workflows:
For Agentic Users, a platform for autonomous agents for the web, the most significant impact and cost savings from using Structured Outputs has been in data extraction. They rely on Pydantic + responseJsonSchema for use cases like extracting attributes related to brand guidelines from image and text examples provided by our users, and parametersJsonSchema for all function declarations.
Alkimi AI creates AI assistants for businesses and education institutions grounded in their knowledge. Using JSON Schema they are able to reliably pass data through a guaranteed schema within their multi-stage LLM pipeline. This helps them efficiently automate the configuration of their AI assistants — “Agent Wizard” — for each of their partners.
These updates are available in the API today so head over to our documentation to learn more.