zod-4

Migrate Zod v3 schemas to Zod v4 APIs in TypeScript projects.

Updated Apr 9, 2025
One-click install
npx skills add https://github.com/D4nitrix13/dotfiles-tmp --skill zod-4-d4nitrix13
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod-4
Source: https://github.com/D4nitrix13/dotfiles-tmp/tree/main/.config/opencode/skill/zod-4
Command: npx skills add https://github.com/D4nitrix13/dotfiles-tmp --skill zod-4-d4nitrix13

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating from Zod v3 to Zod v4 can be error-prone due to breaking changes and updated APIs. This guide consolidates the changes and provides practical migration patterns to keep schemas correct and forward-compatible.

Core Features & Use Cases

  • Migration guidance: highlights the breaking changes from Zod v3 to v4 and provides updated validators (e.g., z.email(), z.uuid(), z.url()) and patterns.
  • Concrete examples: shows updated object schemas, arrays, and refinements to help you convert existing schemas with minimal friction.
  • Use case: upgrade an existing validation layer in a Node/TS project and verify behavior with tests.

Quick Start

Update your Zod v3 schemas to their Zod v4 equivalents and run your validation tests to confirm correctness.

Frequently Asked Questions about zod-4

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate Zod v3 schemas to Zod v4 in TypeScript?

Migrate Zod v3 schemas to v4 by identifying breaking changes and replacing v3 patterns with updated validators like z.email(). Apply Zod v4 API equivalents to object schemas, arrays, and refinements, then run validation tests to confirm correctness.

What are the breaking changes in Zod v4?

Zod v4 breaking changes include updated validator APIs such as z.email(), z.uuid(), and z.url(), replacing previous v3 patterns. Schemas must be updated to enforce compatibility with Zod v4 APIs while preserving runtime validation behavior across backend and frontend code.

Does Zod v4 migration preserve existing runtime validation behavior?

Yes, Zod v4 migration preserves runtime validation behavior by enforcing compatibility with Zod v4 APIs. Existing Zod v3 schemas are updated to v4 equivalents across backend and frontend code, and tests are updated to verify that the original validation behavior remains intact.

What's the best way to update Zod refinements for v4 compatibility?

Update Zod refinements for v4 compatibility by applying migration patterns that replace v3 refinement syntax with v4 equivalents. Concrete examples guide the conversion of object schemas, arrays, and refinements to ensure type-safe schemas with minimal friction.

Can I use Zod v4 migration patterns for both backend and frontend code?

Yes, Zod v4 migration patterns apply to both backend and frontend TypeScript code. The migration identifies and applies Zod v4 changes across the entire project, updating validation layers and tests to ensure type-safe schemas and compatibility with Zod v4 APIs.

Why does my Zod schema fail after upgrading to v4?

Zod schemas fail after upgrading to v4 due to breaking changes and updated APIs that invalidate v3 patterns. Resolve failures by replacing outdated validators with updated Zod v4 equivalents and running validation tests to confirm schema correctness.