Skip to content

Fix Zod version compatibility for SDK users#135

Open
MiguelAtExa wants to merge 1 commit intomasterfrom
fix/zod-peer-dependency
Open

Fix Zod version compatibility for SDK users#135
MiguelAtExa wants to merge 1 commit intomasterfrom
fix/zod-peer-dependency

Conversation

@MiguelAtExa
Copy link
Copy Markdown
Contributor

Moves zod from a bundled dependency to an optional peer dependency (>=3.24.1) and replaces the instanceof ZodType check in zod-utils.ts with duck-type detection (safeParse, parse, _def). Previously, bundling zod as a regular dependency meant users ended up with two copies of zod in their node_modules — theirs and the SDK's — causing instanceof checks to fail silently when users passed their own Zod schemas to outputSchema or summary.schema. The duck-type approach works across any Zod instance or version, and marking the peer dep as optional means users who don't use schema features aren't forced to install zod at all. Also converts the ZodSchema imports in index.ts and research/client.ts to type-only imports so they're erased at compile time.

@oxc
Copy link
Copy Markdown

oxc commented Apr 20, 2026

Zod has a guide on how to support both versions at the same time:

https://zod.dev/library-authors?id=how-to-support-zod-3-and-zod-4-simultaneously

The better solution they recommend, though, is to support standard-schema instead.

From a quick look at the code, it seems the zod schema is converted to a json schema, so the better approach might be to use standard-json-schema and maybe keep a special implementation for zod 4 for backwards compatibility.

In any case, pulling in zod 3 is a show-stopper for me :(

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