Closed manishrc closed 3 months ago
Also, are there any guidelines for the best way to catch validation errors when using streamObject
? I tried using fullStream
, but the Zod validations do not appear there.
I see that onFinish has an error, but wondering if it's possible to abort the stream when Zod validation fails.
@manishrc currently only the final object is validated with the zod schema. You can find tips here: https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling#prompt-engineering-with-tools
My recommendation is to use description()
in those cases.
Description
I'm not certain if the issue lies in how the Zod schema is translated for OpenAI or with the OpenAI model itself. Some Zod validations are not being adhered to. (It would be nice to also get access to the
rawRequest
, similar torawResponse
)For example, the validation
z.number.max(60)
expects a number not higher than 60, but frequently receives higher values. In this particular case, the prompt was explicitly set to bias towards larger numbers to make the issue easier to reproduce, but the problem occurred without such prompts.Code example
Received output:
Additional context
No response