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

Adding .optional() or .partial() to the parent zod schema object with OpenAIs Structured output leads to error #2792

Closed
AnzeKop opened this issue Aug 24, 2024 · 1 comment

Comments

@AnzeKop
Copy link

AnzeKop commented Aug 24, 2024

Description

When passing a schema with .optional() or .partial() at the end of the root zod object combined with OpenAIs structured data the call fails

I_APICallError: Invalid schema for response_format 'response': In context=('properties', 'katzen', 'items'), 'required' is required to be supplied and to be an array including every key in properties

Code example

const openAiModel = openai("gpt-4o-2024-08-06", { structuredOutputs: true })
const schema = z.object({
  id: z.number(),
  type: z.enum(["cat"]),
  name: z.string(),
}).partial()

Additional context

No response

@lgrammel
Copy link
Collaborator

This error is an OpenAI limitation and thrown by the OpenAI API. You can use a stronger model without structured outputs or design you schema differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants