Update — July 10th, 2025Zod If you’d already implemented Zod 4 support according to the best practices described below (e.g. using the
4.0.0 has been released on npm. This completes the incremental rollout process. To add support, bump your peer dependency to include zod@^4.0.0:"zod/v4/core" subpath), then no other code changes should be necessary. This should not require a major version bump in your library.Do I need to depend on Zod?
First things first, make sure you need to depend on Zod at all. If you’re building a library that accepts user-defined schemas to perform black-box validation, you may not need to integrate with Zod specifically. Instead look into Standard Schema. It’s a shared interface implemented by most popular validation libraries in the TypeScript ecosystem (see the full list), including Zod. This spec works great if you accept user-defined schemas and treat them like “black box” validators. Given any compliant library, you can extract inferred input/output types, validate inputs, and get back a standardized error. If you need Zod specific functionality, read on.How to configure peer dependencies?
Any library built on top of Zod should include"zod" in "peerDependencies". This lets your users “bring their own Zod”.
"zod" to your "devDependencies" as well.
How to support Zod 4?
To support Zod 4, update the minimum version for your"zod" peer dependency to ^3.25.0 || ^4.0.0.
Starting with v3.25.0, the Zod 4 core package is available at the "zod/v4/core" subpath. Read the Versioning in Zod 4 writeup for full context on this versioning approach.
"zod/v3"for Zod 3 ✅"zod/v4/core"for the Zod 4 Core package ✅
"zod"— ❌ In 3.x releases, this exports Zod 3. In 4.x releases, this will export Zod 4. Use the permalinks instead."zod/v4"and"zod/v4/mini"— ❌ These subpaths are the homes of Zod 4 Classic and Mini, respectively. If you want your library to work with both Zod and Zod Mini, you should build against the base classes defined in"zod/v4/core".
Do I need to publish a new major version?
No, you should not need to publish a new major version of your library to support Zod 4 (unless you are dropping support for Zod 3, which isn’t recommended). You will need to bump your peer dependency to^3.25.0, thus your users will need to npm upgrade zod. But there were no breaking changes made to Zod 3 between [email protected] and [email protected]; in fact, there were no code changes whatsoever. As no code changes will be required on the part of your users, this does not constitute a breaking change.
How to support Zod 3 and Zod 4 simultaneously?
Starting inv3.25.0, the package contains copies of both Zod 3 and Zod 4 at their respective subpaths. This makes it easy to support both versions simultaneously.
"_zod" property. This property is only defined on Zod 4 schemas.
How to support Zod and Zod Mini simultaneously?
Your library code should only import from"zod/v4/core". This sub-package defines the interfaces, classes, and utilities that are shared between Zod and Zod Mini.
How to accept user-defined schemas?
Accepting user-defined schemas is a fundamental operation for any library built on Zod. This section outlines the best practices for doing so. When starting out, it may be tempting to write a function that accepts a Zod schema like this:Constraining to specific schema types
To constrain the input schema to a specific subclass:Parsing data with schemas
To parse data with the schema, use the top-levelz4.parse/z4.safeParse/z4.parseAsync/z4.safeParseAsync functions. The z4.$ZodType subclass has no methods on it. The usual parsing methods are implemented by Zod and Zod Mini, but are not available in Zod Core.
Best practices
Use semantic versioning carefully
When adding Zod 4 support:- Minor version bump: If you’re adding Zod 4 support while maintaining Zod 3 compatibility
- Major version bump: Only if you’re dropping Zod 3 support entirely
Test against multiple Zod versions
Set up your test suite to run against both Zod 3 and Zod 4 to ensure compatibility:Document Zod version support
Be clear in your README about which versions of Zod your library supports:Avoid relying on internal APIs
Stick to the public API surface as much as possible. Internal implementation details may change between versions. ✅ Good:Examples from the ecosystem
Here are some examples of libraries that have successfully implemented Zod 4 support:- tRPC - Type-safe API framework
- React Hook Form - Form validation
- Fastify Type Provider - Request/response validation