-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Structured JSON output key ordering issue causes incorrect reasoning steps #354
Comments
Hello @yuan-li, |
Thank you @Giom-V |
I'm having this issue as well, where the json is output with alphabetically arranged keys and not in the order specified |
The feature is still in the backlog, but in the meantime, have you tried the thinking model? |
Having this exact issue, and it's not alphabetical. It's a pre-defined, seemingly random order. It's a very bad bug. Like the original post said, it makes it impossible to enforce a specific reasoning flow. |
@yuan-li - does the problem persist even if you use a hard coded Schema instead of a Pydantic Models? might be a temporary by-pass We had different but similar problem that was solved by using a schema and adding a required attribute |
@karayanni This problem persists even if I use a required attribute field. The response did not follow the order specified in that field. |
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: