Google updates Structured Outputs in the Gemini API to expand JSON Schema support and improve the order of properties in responses. Why does this matter to you? Because it makes it easier for models and apps to exchange reliable data without you having to write a thousand validators by hand.
What changes in the Gemini API
The improvements focus on two concrete things: broader compatibility with JSON Schema and preserving the property order defined in the schema. That means the API produces outputs that follow more strictly and predictably what you define, which is key for data extraction and multi-agent pipelines.
In technical terms this applies to all actively supported Gemini models, and starting with Gemini 2.5 there is consistent support also in the OpenAI-compatible API.
Expanded support for JSON Schema
Before, the Gemini API already had a Schema object based on OpenAPI 3.0. Now native JSON Schema support is added, which lets you use popular libraries directly: Pydantic in Python and Zod in JavaScript/TypeScript work out-of-the-box.
They also added several keywords frequently requested by developers:
anyOffor conditional structures or unions.$reffor recursive schemas.minimumandmaximumfor numeric constraints.additionalPropertiesandtype: 'null'for more flexibility.prefixItemsfor arrays with tuple-like behavior.
This expands the expressiveness of schemas and reduces the need for post-processing or ad-hoc validations.
Implicit property ordering
A small-looking update but big in impact: the API now preserves the order of keys as they appear in the schema. Why does order matter? Because many flows expect fields in a logical sequence: forms, logs, steps in an agent. If the model emits fields in the same order as the schema, you can consume that output without reordering it.
This is supported for Gemini 2.5 and up and also in the compatibility API. In practice you'll see examples like content moderation extraction with Pydantic where the output respects the defined layout.
Real use cases and technical examples
Some early partners show how this improves real products:
-
Agentic Users: they reduced costs and improved data extraction quality by combining
PydanticwithresponseJsonSchemato get brand guideline attributes from text and images. -
Alkimi AI: uses JSON Schema to pass reliable data in multi-stage LLM pipelines. That makes it easier to automate assistant setups — their "Agent Wizard" — ensuring each stage receives exactly what it expects.
Minimal JSON Schema example that leverages anyOf and $ref (short representation):
{
"type": "object",
"properties": {
"id": { "type": "string" },
"metadata": {
"$ref": "#/definitions/metadata"
}
},
"definitions": {
"metadata": {
"anyOf": [
{ "type": "null" },
{
"type": "object",
"properties": {
"score": { "type": "number", "minimum": 0, "maximum": 1 }
}
}
]
}
}
}
With this, your pipeline can consume the output directly with Pydantic or Zod and know that fields will come in the order you defined.
How to get started (quick guide)
- Define your JSON Schema with the keywords you need:
anyOf,$ref,minimum,maximum,prefixItems, etc. - In the request to Gemini, use Structured Outputs/responseJsonSchema or the equivalent for functions. Make sure to target Gemini 2.5+ if you need order preservation.
- Validate the response with
PydanticorZod. With native compatibility, the mapping is usually straightforward. - If you work with agents, chain outputs as formatted inputs to avoid extra translation layers.
Impact and considerations
These improvements reduce friction between models and systems that expect structured data. Less ad-hoc parsing, fewer errors from missing fields or unexpected order, and more efficient pipelines.
It's not magic: you still need to design clear schemas, handle validation errors, and consider length or token limits. But now you have more robust tools to ensure the model's output is consistent and processable.
Often the real savings aren't just in latency or token cost, but in the time you stop spending fixing broken integrations. Isn't that what we all look for when automating with AI?
Original source
https://blog.google/technology/developers/gemini-api-structured-outputs
