Does Gemini OpenAI-Compatible Mode Structured Outputs Preserve Key Ordering?

The OpenAI structured output documentation explicitly states:

“When using Structured Outputs, outputs will be produced in the same order as the ordering of keys in the schema.”

However, the Gemini documentation on structured output says:

“When you’re working with JSON schemas in the Gemini API, the order of properties is important. By default, the API orders properties alphabetically and does not preserve the order in which the properties are defined.”

Meanwhile, the Gemini OpenAI-compatible mode documentation says nothing about key ordering.

So I’d like to know: does the OpenAI-compatible mode in Gemini preserve the ordering of keys?

I’m asking because I’m building an AI tabular data generation tool (Tablepilot), which uses the OpenAI SDK for all models. I’m considering allowing users to customize column order—so they can, for example, add a CoT column (see openai structured-outputs chain-of-thought example) and ensure that data is generated for it first.

Hi @yiling, Welcome to the forum!!

Yes, OpenAI-compatible mode in Gemini preserve the ordering of keys. I just checked the example given in the doc, and confirmed it with modifying the fields. There is no issue. If you face any challenges, please reach out.

Thanks

@Govind_Keshari Thanks for the confirmation! It would be great if Google could also include this in the OpenAI compatibility documentation. Since this behavior differs from Gemini’s default, having it documented would give developers confidence that it’s intentional and stable, rather than something that might change or fail unexpectedly.

Personally, I think OpenAI’s Chain of Thought example is a great one why key order can be important in certain cases, maybe Google could consider including similar example in the docs.