generative-ai-go icon indicating copy to clipboard operation
generative-ai-go copied to clipboard

propertyOrdering is missing from Schema

Open orsinium opened this issue 9 months ago • 5 comments

Description of the bug:

According to the docs, the JSON schema supports propertyOrdering but it's not present in the Schema object.

https://ai.google.dev/gemini-api/docs/structured-output?lang=go#property-ordering

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

orsinium avatar Mar 06 '25 14:03 orsinium

I tried to edit Schema in code but it says that the file is autogenerated and I'm not sure what is the source.

orsinium avatar Mar 06 '25 14:03 orsinium

Thanks for bringing this issue up. Do you have a reproducible code snippet that can be used for further triaging?

Annhiluc avatar Mar 24 '25 22:03 Annhiluc

genai.Schema{PropertyOrdering: []string{"a", "b"}} 👀

orsinium avatar Mar 25 '25 07:03 orsinium

Same here, it seems to fill-in the fields in alphabetical order as specified by the docs. This leads to poor behavior for this simple toy example since the "punchline" is filled before the "setup".

model.ResponseMIMEType = "application/json"
model.ResponseSchema = &genai.Schema{
	Type:        genai.TypeObject,
	Description: "Jokes are formatted as JSON objects with setup and punchline fields.",
	Nullable:    false,
	Required:    []string{"setup", "punchline"},
	Properties: map[string]*genai.Schema{
		"setup": &genai.Schema{
			Type:        genai.TypeString,
			Description: "The setup of the joke.",
			Nullable:    false,
		},
		"punchline": &genai.Schema{
			Type:        genai.TypeString,
			Description: "The punchline of the joke.",
			Nullable:    false,
		},
	},
}

resp, err := model.GenerateContent(ctx, genai.Text(`Tell me a joke about tariffs.`))

I am able to force the order by renaming the fields to a_setup and b_punchline.

Also, by looking at the struct in genai.Schema, I am also confused on other schema properties like anyOf, maxItems, minItems, minimum, maximum as referenced by the Schema documentation here: https://ai.google.dev/api/caching#Schema

sontanon avatar Apr 05 '25 01:04 sontanon

This is solved in this SDK: https://github.com/googleapis/go-genai/tree/v0.7.0 I am not sure why there are two competing go SDKs for Google GenAI...

sontanon avatar Apr 05 '25 03:04 sontanon