-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
must be specified when not using one_of using zod.union() on google provider #4725
Comments
I have seen similar with enums. I tried to use the new For reference my schema looks like the following: const MockSchema = z.object({
fieldA: z.string(),
fieldB: z.number(),
fieldC: z.array(z.object({
fieldD: z.enum(['a', 'b', 'c']),
}))
}) And the error looks like: responseBody: '{\n' +
' "error": {\n' +
' "code": 400,\n' +
` "message": "Invalid JSON payload received. Unknown name \\"type\\" at 'generation_config.response_schema.proper
ties[2].value.items.properties[2].value.any_of[0].properties[2].value.items.properties[2].value': Proto field is not rep
eating, cannot start list.\\nInvalid value at 'generation_config.response_schema.properties[2].value.items.properties[2]
.value.any_of[1].type' (type.googleapis.com/google.ai.generativelanguage.v1beta.Type), \\"null\\"",\n` +
' "status": "INVALID_ARGUMENT",\n' +
' "details": [\n' +
' {\n' +
' "@type": "type.googleapis.com/google.rpc.BadRequest",\n' +
' "fieldViolations": [\n' +
' {\n' +
' "field": "generation_config.response_schema.properties[2].value.items.properties[2].value.any_of[0].pro
perties[2].value.items.properties[2].value",\n' +
` "description": "Invalid JSON payload received. Unknown name \\"type\\" at 'generation_config.response_s
chema.properties[2].value.items.properties[2].value.any_of[0].properties[2].value.items.properties[2].value': Proto fiel
d is not repeating, cannot start list."\n` +
' },\n' +
' {\n' +
' "field": "generation_config.response_schema.properties[2].value.items.properties[2].value.any_of[1].typ
e",\n' +
` "description": "Invalid value at 'generation_config.response_schema.properties[2].value.items.propertie
s[2].value.any_of[1].type' (type.googleapis.com/google.ai.generativelanguage.v1beta.Type), \\"null\\""\n` +
' }\n' +
' ]\n' +
' }\n' +
' ]\n' +
' }\n' +
'}\n', Where the I know OpenAI struggles with some complex zod schema which I have to use Anthropic to handle; ie |
I am also running into the same error: "Invalid value at 'generation_config.response_schema.properties[1].value.any_of[1].type' (type.googleapis.com/google.ai.generativelanguage.v1beta.Type)" I think @natac13 is right that the enums are the issue - my |
Does this only happen on the 2.0 models or also on 1.5 models? |
@lgrammel Getting it on all google models - just tested 1.5 pro and 1.5 flash, same thing. I'm also getting a |
I wonder if they changed something - was existing code suddenly broken or are these new schemas? |
I'm not sure, this is actually my first time using the google models so I can't say if it was working before or not - sorry I can't be of more help here! |
I just found this thread: https://discuss.ai.google.dev/t/oneof-in-response-schema/55926 It seems like one_of (zod union) is currently not supported by Google, though it's supported by OpenAI. |
I was trying out gemini-2.0 only.
Not new schema. Just a schema that was working with 4o and 4o-mini, o1 also fails on the comlexitity of the schema. I have found that openai does the 'best' with a huge generation with a somewhat simple schema. It can contain enums though. When I need |
Optimal DX in this case would be for This approach is consistent with the ai sdks mission (https://sdk.vercel.ai/docs/introduction#why-use-the-ai-sdk). |
Description
Related issue: #4153
Error doesn't happen if structuredOutputs: false
Code example
const model = google('gemini-2.0-flash', { structuredOutputs: true })
const mainSchema = z.array(z.union([subSchema1, subSchema2]))
const response = await generateObject({
model: this.model,
messages,
schema: z.object({
chain_of_thought: z.string(),
locator: mainSchema,
}),
});
AI provider
@ai-sdk/google@1.1.10
Additional context
No response
The text was updated successfully, but these errors were encountered: