vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid

Home Page:https://sdk.vercel.ai/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

structuredOutput fails if schemas use `.optional()` or `.nullish()`, should be `.nullable()`.

MaxLeiter opened this issue · comments

          Just a heads up for others, if you're getting errors like this with `structuredOutputs`, replace `.optional()` or `.nullish()` in your schema with `.nullable()`.
AI_APICallError: Invalid schema for response_format 'response': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'foo'

Originally posted by @brc-dd in #2573 (comment)

This is a limitation of the OpenAI implementation. Other providers will not have this. Therefore I don't want to put in any magic, it's imo on the user / OpenAI to solve this.

Potential solutions:
a) clear error messages
b) docs around this, e.g. tips & troubleshooting