Skip to content

fix: bump zod to fix use with Google APIs + .literal() #6609

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

Merged
merged 6 commits into from
Jun 4, 2025

Conversation

gr2m
Copy link
Collaborator

@gr2m gr2m commented Jun 3, 2025

Background

Follow up to #6421.

One known issue is that zod v4's .toJSONSchema() does not set "type" for .literal() types, which causes problems with Google's APIs, see

Since the fix was now merged and released in zod, we are bumping the minimal zod version.

Summary

Bump zod to v3.25.49

Verification

I updated the example at examples/ai-core/src/generate-object/google-vertex.ts to use import { z } from 'zod/v4'; and name: z.literal('Lasagna'),. It currently fails on v5, but works with the patch in this pull request

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Related Issues

#5682


async function main() {
const result = await generateObject({
model: vertex('gemini-1.5-pro'),
schema: z.object({
recipe: z.object({
name: z.string(),
name: z.literal('Lasagna'),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it wouldn't hurt to persist the change I used to verify the fix since to reduce the chance of future regressions.

@gr2m gr2m marked this pull request as ready for review June 3, 2025 22:36
@lgrammel
Copy link
Collaborator

lgrammel commented Jun 4, 2025

Would a unit test make sense (since it's a fix, to prevent regressions)? i have some for zod3 to json conversions.

@gr2m
Copy link
Collaborator Author

gr2m commented Jun 4, 2025

Would a unit test make sense (since it's a fix, to prevent regressions)?

good idea, added via 9346f21

},
"text": {
"const": "hello",
"type": "string",
Copy link
Collaborator Author

@gr2m gr2m Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the relevant line that was missing in generated JSON Schemas from zod v4 prior the bump of zod to 3.25.49.

"two",
"three",
],
"type": "string",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a unit test for z.enum() which was fixed in [email protected], but we didn't add a unit test yet.

@gr2m gr2m merged commit 8255639 into v5 Jun 4, 2025
8 checks passed
@gr2m gr2m deleted the bump-zod-to-fix-literal-type-in-json-schema branch June 4, 2025 16:12
lgrammel pushed a commit that referenced this pull request Jun 5, 2025
# Releases
## [email protected]

### Major Changes

-   9ae327d: chore (ui): replace chat store concept with chat instances

### Patch Changes

-   8255639: ### Fix use with Google APIs + zod v4's `.literal()` schema

Before
[[email protected]](https://github.com/colinhacks/zod/releases/tag/v3.25.49),
requests to Google's APIs failed due to a missing `type` in the provided
schema. The problem has been resolved for the `ai` SDK by bumping our
`zod` peer dependencies to `^3.25.49`.

    pull request: <#6609>

-   Updated dependencies [26b6dd0]

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Minor Changes

-   b94b4ed: add live search

### Patch Changes

-   107cd62: Add native XAI chat language model implementation
-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

- c87b7e4: feat (provider/amazon-bedrock): add Claude 4 model ids
(claude-sonnet-4-20250514-v1:0, claude-opus-4-20250514-v1:0)
-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   362b048: add web search tool support
-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   b248983: feat (@ai-sdk/fal): support new Flux Kontext models
-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   26b6dd0: feat (providers/gateway): include deployment and request id
-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [362b048]
-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [8255639]
-   Updated dependencies [9ae327d]
    -   [email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [8255639]
-   Updated dependencies [9ae327d]
    -   [email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   811dff3: release alpha.9

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [8255639]
-   Updated dependencies [9ae327d]
    -   [email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [8255639]
-   Updated dependencies [9ae327d]
-   Updated dependencies [811dff3]
    -   [email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [8255639]
-   Updated dependencies [9ae327d]
    -   [email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [811dff3]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]
    -   @ai-sdk/[email protected]

## @ai-sdk/[email protected]

### Patch Changes

-   Updated dependencies [8255639]
-   Updated dependencies [9ae327d]
    -   [email protected]
    -   @ai-sdk/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants