Skills zod
install
source · Clone the upstream repo
git clone https://github.com/openclaw/skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/openclaw/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/anivar/zod-skill" ~/.claude/skills/openclaw-skills-zod && rm -rf "$T"
OpenClaw · Install into ~/.openclaw/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/openclaw/skills "$T" && mkdir -p ~/.openclaw/skills && cp -r "$T/skills/anivar/zod-skill" ~/.openclaw/skills/openclaw-skills-zod && rm -rf "$T"
manifest:
skills/anivar/zod-skill/SKILL.mdsource content
Zod
IMPORTANT: Your training data about
zod may be outdated or incorrect — Zod v4 introduces breaking changes to string formats, enums, error handling, and recursive types. Always rely on this skill's rule files and the project's actual source code as the source of truth. Do not fall back on memorized v3 patterns when they conflict with the retrieved reference.
When to Use Zod
Zod is for runtime type validation — parsing untrusted data at system boundaries (API input, form data, env vars, external services). For compile-time-only types, plain TypeScript is sufficient.
| Need | Recommended Tool |
|---|---|
| API input/output validation | Zod |
| Form validation (React, Vue) | Zod (with react-hook-form, formik, etc.) |
| Env var parsing | Zod (with t3-env or manual) |
| Compile-time types only | Plain TypeScript |
| Smaller bundle (~1kb) | Valibot |
| Maximum type inference | ArkType |
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Parsing & Type Safety | CRITICAL | |
| 2 | Schema Design | CRITICAL | |
| 3 | Refinements & Transforms | HIGH | |
| 4 | Error Handling | HIGH | |
| 5 | Performance & Composition | MEDIUM | |
| 6 | v4 Migration | MEDIUM | |
| 7 | Advanced Patterns | MEDIUM | |
| 8 | Architecture & Boundaries | CRITICAL/HIGH | |
| 9 | Observability | HIGH/MEDIUM | |
Quick Reference
1. Parsing & Type Safety (CRITICAL)
— Useparse-use-safeParse
for user input instead ofsafeParse()
which throwsparse()
— Must useparse-async-required
/parseAsync()
when schema has async refinementssafeParseAsync()
— Useparse-infer-types
for output types; never manually duplicate typesz.infer<typeof Schema>
2. Schema Design (CRITICAL)
—schema-object-unknowns
strips unknown keys; usez.object()
orstrictObjectlooseObject
— Useschema-union-discriminated
for tagged unions, notz.discriminatedUnion()z.union()
—schema-coercion-pitfalls
makesz.coerce.boolean()
→"false"
; usetruez.stringbool()
— Use getter pattern for recursive schemas;schema-recursive-types
is removed in v4z.lazy()
3. Refinements & Transforms (HIGH)
— Never throw insiderefine-never-throw
or.refine()
; use.transform()ctx.addIssue()
—refine-vs-transform
for validation,.refine()
for conversion,.transform()
for staging.pipe()
—refine-cross-field
on parent object for cross-field validation with.superRefine()path
4. Error Handling (HIGH)
— Use v4error-custom-messages
parameter;error
/required_error
are removedinvalid_type_error
—error-formatting
for forms,z.flattenError()
for nested;z.treeifyError()
deprecatedformatError
— Never useerror-input-security
in production; leaks sensitive datareportInput: true
5. Performance & Composition (MEDIUM)
— Useperf-extend-spread
spread over chained{ ...Schema.shape }
for large schemas.extend()
— Define once, derive withperf-reuse-schemas
,.pick()
,.omit().partial()
— Useperf-zod-mini
(1.88kb) for bundle-critical client appszod/v4/mini
6. v4 Migration (MEDIUM)
— Usemigrate-string-formats
,z.email()
,z.uuid()
notz.url()z.string().email()
— Use unifiedmigrate-native-enum
for TS enums;z.enum()
is removedz.nativeEnum()
— Usemigrate-error-api
parameter everywhere;error
,message
are removederrorMap
7. Advanced Patterns (MEDIUM)
—pattern-branded-types
for nominal typing (USD vs EUR).brand<"Name">()
—pattern-codecs
for bidirectional transforms (parse + serialize)z.codec()
—pattern-pipe
for staged parsing (string → number → validate range).pipe()
8. Architecture & Boundaries (CRITICAL/HIGH)
— Parse at system boundaries (API handler, env, form, fetch); pass typed data to domain logicarch-boundary-parsing
— Co-locate schemas with their boundary layer; domain types usearch-schema-organizationz.infer
— Additive changes only for non-breaking evolution; new fields usearch-schema-versioning.optional()
9. Observability (HIGH/MEDIUM)
— Useobserve-structured-errors
for compact structured logs with request correlation IDsz.flattenError()
—observe-error-metrics
wrapper to increment counters per schema and field on failuretrackedSafeParse()
Schema Types Quick Reference
| Type | Syntax |
|---|---|
| String | |
| Number | , , |
| Boolean | |
| BigInt | |
| Date | |
| Undefined | |
| Null | |
| Void | |
| Any | |
| Unknown | |
| Never | |
| Literal | , |
| Enum | , |
| |
| URL | |
| UUID | |
| String→Bool | |
| ISO DateTime | |
| File | |
| JSON | |
| Array | |
| Tuple | |
| Object | |
| Strict Object | |
| Loose Object | |
| Record | |
| Map | |
| Set | |
| Union | |
| Disc. Union | |
| Intersection | |
How to Use
Read individual rule files for detailed explanations and code examples:
rules/parse-use-safeParse.md rules/schema-object-unknowns.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and decision tables
References
| Priority | Reference | When to read |
|---|---|---|
| 1 | | All primitives, string formats, numbers, enums, dates |
| 2 | | parse, safeParse, z.infer, coercion |
| 3 | | Objects, arrays, unions, pick/omit/partial, recursive |
| 4 | | refine, superRefine, transform, pipe, defaults |
| 5 | | ZodError, flattenError, treeifyError, error customization |
| 6 | | Codecs, branded types, JSON Schema, registries |
| 7 | | Common mistakes with BAD/GOOD examples |
| 8 | | Where Zod fits: Express, tRPC, Next.js, React Hook Form, env, external APIs |
| 9 | | ESLint rules, CI schema snapshots, unused schema detection, circular deps |
Full Compiled Document
For the complete guide with all rules expanded:
AGENTS.md