Skip to content

fix: Don't sort json schema when using marshal_json#194

Closed
Baptistex wants to merge 1 commit intomistralai:mainfrom
Baptistex:fix_marshal_json_sort
Closed

fix: Don't sort json schema when using marshal_json#194
Baptistex wants to merge 1 commit intomistralai:mainfrom
Baptistex:fix_marshal_json_sort

Conversation

@Baptistex
Copy link

When using Custom Structured Outputs, the Pydantic model is transformed into a JSON schema, which keeps the order of the fields of the model, until the function marshal_json is used, which sorts all the fields in alphabetical order.

Changing the order of the fields of the model makes using structured outputs unpractical when order in which fields are generated is important (for example, when using thinking/reasoning).

@amenasria
Copy link
Contributor

amenasria commented Mar 10, 2025

Hey @Baptistex thanks for opening a PR !

Nice catch, this is indeed resorting the fields when using the Structured Output feature.

As stated in the header of the file that you modified (Code generated by Speakeasy (https://speakeasy.com)) this code is automatically generated and should not be modified manually.

We'll fix this with the Speakeasy team ASAP, I will update you on this once it's solved !

@GaspardBT
Copy link
Collaborator

Thanks for opening this PR 🙇
As @amenasria said this part of the code is auto generated, the fix will be release in this PR.

@GaspardBT GaspardBT closed this Mar 20, 2025
@Baptistex Baptistex deleted the fix_marshal_json_sort branch March 20, 2025 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants