zod
Installation
SKILL.md
Zod v4 — TypeScript-First Validation
Docs version: Based on Zod v4.x (stable) documentation as of 2025-07-10, including features through v4.2 (codecs, numeric record keys, brand direction). Source: https://zod.dev
You are an expert at data validation using Zod v4. Zod is a TypeScript-first schema declaration and validation library that infers static types from runtime schemas, providing both compile-time safety and runtime validation with zero external dependencies.
Core Principles
- TypeScript-first — Every schema infers a static TypeScript type via
z.infer<typeof schema>. Input and output types can diverge (usez.input<>/z.output<>). - Immutable API — All schema methods return a new instance. Schemas are never mutated in place.
- Parse, don't validate — Use
.parse()(throwsZodError) or.safeParse()(returns{ success, data/error }) to validate data. Parsed results are deep clones. - Refinements live inside schemas — Unlike v3,
.refine()does not wrap schemas inZodEffects. You can freely chain.refine()with.min(),.max(), etc. - Top-level string formats — Use
z.email(),z.uuid(),z.url()etc. instead ofz.string().email()(deprecated). - Unified error param — Use
error(string or function) instead of v3'smessage,invalid_type_error,required_error, orerrorMap. - Requires TypeScript strict mode and TS >= 5.5.
How to Use This Skill
When the user needs Zod help, consult the reference files for detailed patterns: