Expert guidance on Zod v4 validation library including breaking changes from v3, migration patterns, core API usage, and common validation patterns. Use when working with Zod schemas, validation, type inference, or migrating from Zod v3.
Inherits all available tools
Additional assets for this skill
This skill inherits all available tools. When active, it can use any tool Claude has access to.
references/common-patterns.mdreferences/core-api.mdreferences/migration-from-v3.mdThis skill provides comprehensive guidance on using Zod v4, TypeScript's leading validation library. It covers breaking changes from v3, migration patterns, core API usage, and real-world validation patterns.
Use this skill when:
| Task | Reference Document |
|---|---|
| Migrating from Zod v3 | references/migration-from-v3.md |
| Core API and primitives | references/core-api.md |
| Real-world patterns | references/common-patterns.md |
CRITICAL: Always review these when working with Zod v4:
error parameter instead of message, invalid_type_error, required_errorz.email() not z.string().email())z.function({ input, output }).implement().issues instead of .errors, z.treeifyError() for formattingz.strictObject() and z.looseObject() instead of .strict() and .passthrough()z.object({ ...Base.shape, ... })) instead of .merge() or .extend()z.record(keySchema, valueSchema).int() enforces safe rangeSee references/migration-from-v3.md for complete migration guide.
import { z } from 'zod/v4';
// Simple schema
const userSchema = z.object({
name: z.string().min(1),
email: z.email(),
age: z.number().int().positive(),
});
// Parse with error handling
const result = userSchema.safeParse(data);
if (!result.success) {
console.error(result.error.issues);
}
// Automatically infer TypeScript type from schema
type User = z.infer<typeof userSchema>;
// { name: string; email: string; age: number }
const passwordSchema = z
.string()
.min(8, { error: 'Password must be at least 8 characters' })
.regex(/[A-Z]/, { error: 'Must contain uppercase letter' })
.regex(/[0-9]/, { error: 'Must contain number' });
.safeParse() for user input - Never let validation errors crash your appz.email() not z.string().email() (v4 pattern)z.strictObject() - Catch typos and unexpected fieldsWhen working with Zod:
z.infer<typeof schema> for TypeScript types.safeParse() and handle errors gracefully