Skip to content

Property Order in Parameters jumbled by deep marshalling to Map. Breaks temperature and two-pass generation techniques #644

@n4ng4

Description

@n4ng4

The SDK jumbles up the order of fields in parameter schema json by running it through this line: https://github.com/googleapis/go-genai/blob/main/models.go#L4063C1-L4063C36 which converts the inputs to a nested map, which in golang do not have any ordering.
This breaks the core underlying feature of the model that it preserves generation order: https://blog.google/technology/developers/gemini-api-structured-outputs/

This also breaks stability of output when 0 temperature is used because the fields are jumbled by the map which makes the sequence of input tokens different.

Environment details

  • Programming language: Golang
  • OS: Mac Tahoe, Windows 11, WSL (Ubuntu)
  • Language runtime version: go1.24.2 linux/amd64
  • Package version: v1.38.0

Steps to reproduce

  1. Use 'SendMessage' API with any function call that takes a json schema with 2 or more properties
  2. https://github.com/googleapis/go-genai/blob/main/models.go#L4063C1-L4063C36 jumbles up the order before making the http request

Converting to a string with preserved order doesn't work either, the api errors out returning status 400. Using Google AI Studio, propertyOrder field doesn't seem to work either.

IMO this seems to be blocking issue and should have higher priority.

Metadata

Metadata

Labels

api:gemini-apiIssues related to Gemini APIpriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions