Skip to content
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 - error on structured output using zod on google provider #4153

Open
cloudycotton opened this issue Dec 19, 2024 · 1 comment
Assignees
Labels
ai/provider bug Something isn't working

Comments

@cloudycotton
Copy link

cloudycotton commented Dec 19, 2024

Description

{
  "error": {
    "code": 400,
    "message": "* GenerateContentRequest.generation_config.response_schema.properties[evening_routines].items.type: must be specified when not using one_of\n",
    "status": "INVALID_ARGUMENT"
  }
}

This is the error I get when I try to stream a structured response using the schema below on google-experimental-1206 model.

Code example

export const Product = z.object({
  name: z.string(),
  category: z.string(),
  description: z.string(),
  key_ingredients: z.string(),
  usage_instructions: z.string(),
  precautions: z.string(),
});

export const Prescription = z.object({
  morning_routines: z.array(Product),
  evening_routines: z.array(Product),
  lifestyle_changes: z.array(z.string()),
  treatment_notes: z.string(),
});

AI provider

^4.0.20 and 1.0.10 for google provider.

const response = await streamObject({
      model: google("gemini-exp-1206"),
      messages: [], // removed for brevity
      schema: Prescription,
    });

|

Additional context

No response

@cloudycotton cloudycotton added the bug Something isn't working label Dec 19, 2024
@cloudycotton cloudycotton changed the title must be specified when not using one_of - error on structured output using zod on google provider using gemini-1206 must be specified when not using one_of - error on structured output using zod on google provider Dec 19, 2024
@shaper
Copy link
Contributor

shaper commented Dec 20, 2024

Hi there, we are looking into this, thanks for raising.

In the immediate term as a workaround, it looks like if you define separate schemas for Morning and Evening products (even if the definition is the same) it will fix the issue.

  // Define separate Product schemas for morning and evening routines
  const MorningProduct = z.object({
    name: z.string(),
    category: z.string(),
    description: z.string(),
    key_ingredients: z.string(),
    usage_instructions: z.string(),
    precautions: z.string(),
  });

  const EveningProduct = z.object({
    name: z.string(),
    category: z.string(),
    description: z.string(),
    key_ingredients: z.string(),
    usage_instructions: z.string(),
    precautions: z.string(),
  });

  const Prescription = z.object({
    morning_routines: z.array(MorningProduct),
    evening_routines: z.array(EveningProduct),
    lifestyle_changes: z.array(z.string()),
    treatment_notes: z.string(),
  });

Another workaround is to disable structured outputs:

    model: google('gemini-exp-1206', {
      structuredOutputs: false,
    }),

@shaper shaper self-assigned this Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/provider bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants