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:
