zod-validation
Original:🇺🇸 English
Translated
Zod v4 schema validation for TypeScript. Covers primitives, string formats, objects, arrays, unions, coercion, transforms, refinements, parsing, type inference, error customization, JSON Schema, file validation, and metadata. Use when writing schemas, validating input, parsing data, inferring types, or converting schemas with Zod.
3installs
Sourceoakoss/agent-skills
Added on
NPX Install
npx skill4agent add oakoss/agent-skills zod-validationTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Zod Validation (v4)
Type-safe schema validation for TypeScript. Zod v4 introduces top-level format functions, , date formats, transforms, , , getter-based recursive types, , and the unified function.
z.stringbool()z.iso.*z.overwrite()z.file()z.toJSONSchema().meta()errorPackage: (also for smaller bundles)
zodzod/miniQuick Reference
| Pattern | Usage |
|---|---|
| Define object schemas |
| Primitive types |
| Top-level string formats (v4) |
| ISO date/time formats (v4) |
| Fixed-width number formats (v4) |
| Template literal type validation (v4) |
| Enums and literals |
| Union types |
| Array and tuple types |
| Key-value collections |
| Optional and nullable modifiers |
| Default values and fallbacks |
| Pre-parse default (parsed through schema, v4) |
| Type coercion before validation |
| String-to-boolean parsing (v4) |
| Output transforms |
| Chain schemas (output feeds next input) |
| Custom validation logic |
| Validate and extract data |
| Extract TypeScript type from schema |
| Input vs output types with transforms |
| File instance validation (v4) |
| Convert schema to JSON Schema (v4) |
| Attach metadata to schemas (v4) |
| Human-readable error formatting (v4) |
| Structured error tree (replaces .format(), v4) |
| Typed schema registry (v4) |
| Unified error customization (v4) |
| Getter-based recursion | Recursive types without |
| Global schema metadata registry (v4) |
| Internationalized error messages (v4) |
Common Mistakes
| Mistake | Fix |
|---|---|
| |
| |
Using | Use |
Forgetting | Add when field may be undefined |
| Use |
| Use |
Missing | Empty strings pass |
| |
| |
| Use getter syntax in v4 (retains object methods) |
| Use unified |
| Function-as-second-arg overload removed; use |
| Replaced by |
| v4 requires two args: |
| Deprecated; use |
| v4 |
Delegation
Use this skill for Zod schema definition, validation, parsing, type inference, coercion, error formatting, metadata, and JSON Schema conversion. For form integration, delegate to the tanstack-form skill.
References
- Schema Types — primitives, string formats, number formats, template literals, objects, arrays, enums, unions, records, optional, nullable
- Transforms and Parsing — coercion, stringbool, transforms, overwrite, pipe, refinements, parsing, type inference
- Error Handling — unified error function, prettifyError, treeifyError, ZodError, error formatting, internationalization
- Common Patterns — form validation, API responses, environment variables, schema composition, recursive types, branded types
- Metadata and JSON Schema — meta, describe, globalRegistry, toJSONSchema, file validation, Zod Mini