Structured JSON output key ordering issue causes incorrect reasoning steps #354
Labels
status:pending implementation
Feature request pending implementation from the Eng team
type:feature request
New feature request/enhancement
Description of the bug:
I’ve encountered a bug when using the structured output feature with the Gemini model. Specifically, I noticed that json keys in the returned response appear sorted alphabetically rather than in the order defined by my provided schema. This seems to interfere with the chain-of-thought reasoning steps.
Actual vs expected behavior:
I just copied the example from OpenAI (https://platform.openai.com/docs/guides/structured-outputs#chain-of-thought)
The response is
Here, the final answer appears before steps, which disrupted the reasoning steps and resulted in an incorrect final answer. It implies that the keys might be sorted alphabetically, so a workaround would be like this:
And the response is as expected this time:
Any other information you'd like to share?
This behavior suggests that the keys may be sorted alphabetically internally, rather than following the schema order. It would be helpful if the model could preserve the original field order to maintain the intended reasoning flow.
The text was updated successfully, but these errors were encountered: