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

Zod .transform() not being called when output="array" #3635

Open
sp88011 opened this issue Nov 12, 2024 · 0 comments
Open

Zod .transform() not being called when output="array" #3635

sp88011 opened this issue Nov 12, 2024 · 0 comments
Labels
ai/core bug Something isn't working

Comments

@sp88011
Copy link

sp88011 commented Nov 12, 2024

Description

I noticed that when the output mode is array, then none of the .transform() methods on the schema will be called.

Code example

Here's a relevant example I expect many people to run into (working with dates):

const openAIModel = openai("gpt-4o-mini");

const { object } = await generateObject({
    model: openAIModel,
    output: "array",
    schema: z.object( { date: z.string().transform((x)=>new Date(x)) } ),
    prompt: "Get the date from the text",
  });

While Typescript thinks that object.date is of type Date, in reality it is always of type string. The transformation doesn't happen.

AI provider

10.2.4

Additional context

I tried applying any other transformation, like adding a completely new property but those transformations also don't happen. I believe the entire transform() method is just ignored.

@sp88011 sp88011 added the bug Something isn't working label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/core bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants