zod
4.6.7 · 12 Oct 2026MIT468.6M / weekRepositoryHomepagenpmAtom feed
4.6.7 is the newest release of 4.x.
Summary· from the note as AI read it
Migration neededRead before upgrading: 8 changes to make.
Before you upgrade
- Strict object intersections now accept keys known to either side; check validationTo check
- Strict object intersections now accept keys known to either side; check validationTo check
- Avoid .pick()/.omit() on refined object schemas; rebuild from shape
- Avoid .pick()/.omit() on refined object schemas; rebuild from shape
- Use .safeExtend() when overwriting properties on refined object schemas
- Use .safeExtend() when overwriting properties on refined object schemas
- Ensure keys passed to .pick()/.omit() exist in the schema
- Ensure keys passed to .pick()/.omit() exist in the schema
New
z.xor()— exclusive union- A new exclusive union type that requires exactly one option to match. Unlike
z.union()which passes if any option matches,z.xor()fails if zero or more than one option matches. - When converted to JSON Schema,
z.xor()producesoneOfinstead ofanyOf. z.looseRecord()— partial record validation- A new record variant that only validates keys matching the key schema, passing through non-matching keys unchanged. This is used to represent
patternPropertiesin JSON Schema.
In short
9 breaking33 new2 faster10 fixed1 internal
- BreakingTo check
More ergonomic intersections
- BreakingTo check
When intersecting schemas that include
z.strictObject(), Zod 4 now only rejects keys that are unrecognized by both sides of the intersection. Previously, any unrecognized key from either side would cause an error. - Breaking
.pick()and.omit()disallowed on object schemas containing refinements - Breaking
Using
.pick()or.omit()on object schemas with refinements now throws an error. Previously, this would silently drop the refinements, leading to unexpected behavior. - Breaking
overwriting properties with
.extend()disallowed on object schemas with refinements - Breaking
Similarly,
.extend()will throws on schemas with refinements if you are overwriting existing properties. - Breaking
Stricter object masking methods
- Breaking
Object masking methods (
.pick(),.omit()) now validate that the keys provided actually exist in the schema:
Security
1 advisory affects 4.3.0; 4.6.6 fixes them
- HighZod can exhaust memory while validating oversized constrained collectionsGHSA-mrhx-c7xc-m3w5 · 1 Oct 2026Fixed in 4.6.6
Release note
This is Zod's biggest release since 4.0. It addresses several of Zod's longest-standing feature requests.
z.fromJSONSchema()
Convert JSON Schema to Zod (#5534, #5586)
You can now convert JSON Schema definitions directly into Zod schemas. This function supports JSON Schema "draft-2020-12", "draft-7", "draft-4", and OpenAPI 3.0.
import * as z from "zod";
const schema = z.fromJSONSchema({
type: "object",
properties: {
name: { type: "string", minLength: 1 },
age: { type: "integer", minimum: 0 },
},
required: ["name"],
});
schema.parse({ name: "Alice", age: 30 }); // ✅The API should be considered experimental. There are no guarantees of 1:1 "round-trip soundness": MySchema > z.toJSONSchema() > z.fromJSONSchema(). There are several features of Zod that don't exist in JSON Schema and vice versa, which makes this virtually impossible.
Features supported:
All primitive types (
string,number,integer,boolean,null,object,array)String formats (
email,uri,uuid,date-time,date,time,ipv4,ipv6, and more)Composition (
anyOf,oneOf,allOf)Object constraints (
additionalProperties,patternProperties,propertyNames)Array constraints (
prefixItems,items,minItems,maxItems)$reffor local references and circular schemasCustom metadata is preserved
z.xor() — exclusive union
A new exclusive union type that requires exactly one option to match. Unlike z.union() which passes if any option matches, z.xor() fails if zero or more than one option matches.
const schema = z.xor([z.string(), z.number()]);
schema.parse("hello"); // ✅
schema.parse(42); // ✅
schema.parse(true); // ❌ zero matchesWhen converted to JSON Schema, z.xor() produces oneOf instead of anyOf.
z.looseRecord() — partial record validation
A new record variant that only validates keys matching the key schema, passing through non-matching keys unchanged. This is used to represent patternProperties in JSON Schema.
const schema = z.looseRecord(z.string().regex(/^S_/), z.string());
schema.parse({ S_name: "John", other: 123 });
// ✅ { S_name: "John", other: 123 }
// only S_name is validated, "other" passes through.exactOptional() — strict optional properties
A new wrapper that makes a property key-optional (can be omitted) but does not accept undefined as an explicit value.
const schema = z.object({
a: z.string().optional(), // accepts `undefined`
b: z.string().exactOptional(), // does not accept `undefined`
});
schema.parse({}); // ✅
schema.parse({ a: undefined }); // ✅
schema.parse({ b: undefined }); // ❌This makes it possible to accurately represent the full spectrum of optionality expressible using exactOptionalPropertyTypes.
.apply()
A utility method for applying arbitrary transformations to a schema, enabling cleaner schema composition.
const setCommonChecks = <T extends z.ZodNumber>(schema: T) => {
return schema.min(0).max(100);
};
const schema = z.number().apply(setCommonChecks).nullable();.brand() cardinality
The .brand() method now accepts a second argument to control whether the brand applies to input, output, or both. Closes #4764, #4836.
// output only (default) z.string().brand<"UserId">(); // output is branded (default) z.string().brand<"UserId", "out">(); // output is branded z.string().brand<"UserId", "in">(); // input is branded z.string().brand<"UserId", "inout">(); // both are branded
Type predicates on .refine()
The .refine() method now supports type predicates to narrow the output type:
const schema = z.string().refine((s): s is "a" => s === "a"); type Input = z.input<typeof schema>; // string type Output = z.output<typeof schema>; // "a"
ZodMap methods: min, max, nonempty, size
ZodMap now has parity with ZodSet and ZodArray:
const schema = z.map(z.string(), z.number()) .min(1) .max(10) .nonempty(); schema.size; // access the size constraint
.with() alias for .check()
A new .with() method has been added as a more readable alias for .check(). Over time, more APIs have been added that don't qualify as "checks". The new method provides a readable alternative that doesn't muddy semantics.
z.string().with( z.minLength(5), z.toLowerCase() ); // equivalent to: z.string().check( z.minLength(5), z.trim(), z.toLowerCase() );
z.slugify() transform
Transform strings into URL-friendly slugs. Works great with .with():
// Zod
z.string().slugify().parse("Hello World"); // "hello-world"
// Zod Mini
// using .with() for explicit check composition
z.string().with(z.slugify()).parse("Hello World"); // "hello-world"z.meta() and z.describe() in Zod Mini
Zod Mini now exports z.meta() and z.describe() as top-level functions for adding metadata to schemas:
import * as z from "zod/mini";
// add description
const schema = z.string().with(
z.describe("A user's name"),
);
// add arbitrary metadata
const schema2 = z.number().with(
z.meta({ deprecated: true })
);More ergonomic intersections #5587
When intersecting schemas that include z.strictObject(), Zod 4 now only rejects keys that are unrecognized by both sides of the intersection. Previously, any unrecognized key from either side would cause an error.
This means keys that are recognized by at least one side of the intersection will now pass validation:
const A = z.strictObject({ a: z.string() });
const B = z.object({ b: z.string() });
const C = z.intersection(A, B);
// Keys recognized by either side now work
C.parse({ a: "foo", b: "bar" }); // ✅ { a: "foo", b: "bar" }
// Extra keys are stripped (follows strip behavior from B)
C.parse({ a: "foo", b: "bar", c: "extra" }); // ✅ { a: "foo", b: "bar" }When both sides are strict, only keys unrecognized by both sides will error:
const A = z.strictObject({ a: z.string() });
const B = z.strictObject({ b: z.string() });
const C = z.intersection(A, B);
// Keys recognized by either side work
C.parse({ a: "foo", b: "bar" }); // ✅
// Keys unrecognized by BOTH sides error
C.parse({ a: "foo", b: "bar", c: "extra" });
// ❌ ZodError: Unrecognized key: "c"New locales
Armenian (
am)Uzbek (
uz)
import * as z from "zod";
import { uz } from "zod/locales";
z.config(uz());Bug fixes
All of these changes fix soundness issues in Zod. As with any bug fix there's some chance of breakage if you were intentionally or unintentionally relying on this unsound behavior.
.pick() and .omit() disallowed on object schemas containing refinements
Using .pick() or .omit() on object schemas with refinements now throws an error. Previously, this would silently drop the refinements, leading to unexpected behavior.
const schema = z.object({
password: z.string(),
confirmPassword: z.string(),
}).refine(data => data.password === data.confirmPassword);
schema.pick({ password: true });
// 4.2: refinement silently dropped ⚠️
// 4.3: throws error ❌Migration: The easiest way to migrate is to create a new schema using the shape of the old one.
const newSchema = z.object(schema.shape).pick({ ... })overwriting properties with.extend() disallowed on object schemas with refinements
Similarly, .extend() will throws on schemas with refinements if you are overwriting existing properties.
const schema = z.object({
a: z.string()
}).refine(/* ... */);
schema.extend({ a: z.number() }); // 4.3: throws error ❌Instead you can use .safeExtend(), which statically ensures that you aren't changing the type signature of any pre-existing properties.
const schema = z.object({
a: z.string(),
}).refine(/* ... */);
schema.safeExtend({
a: z.string().min(5).max(10)
}); // ✅ allows overwrite, preserves refinementStricter object masking methods
Object masking methods (.pick(), .omit()) now validate that the keys provided actually exist in the schema:
const schema = z.object({ a: z.string() });
// 4.3: throws error for unrecognized keys
schema.pick({ nonexistent: true });
// error: unrecognized key: "nonexistent"Additional changes
Fixed JSON Schema generation for
z.iso.timewith minute precisionFixed error details for tuples with extraneous elements
Fixed
includesmethod params typing to acceptstring | $ZodCheckIncludesParamsFixed numeric formats error messages to be inclusive
Fixed
implementAsyncinferred type to always be a promiseTightened E.164 regex to require a non-zero leading digit and 7–15 digits total
Fixed Dutch (nl) error strings
Convert
Dateinstances to numbers inminimum/maximumchecksImproved numeric keys handling in
z.record()Lazy initialization of
~standardschema propertyFunctions marked as
@__NO_SIDE_EFFECTS__for better tree-shakingImproved metadata tracking across child-parent relationships
Improved locale translation approach
Dropped id uniqueness enforcement at registry level
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.