Back to Skills

zod

Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).

145stars8forksUpdated 5/21/2026

Security Assessment

Medium Risk(50/100)

Detected risks:

Secret Exposure([references/error-avoid-throwing-in-refine.md] password =, [references/refine-add-path.md] password =, [references/refine-vs-superrefine.md] password =)
Sensitive File Access([references/parse-use-safeparse.md] .env, [references/parse-validate-early.md] .env)
Security Score50/100

About zod

The zod skill provides a structured guide to implementing Zod schema validation in TypeScript projects, focusing on type safety, data parsing, and error handling. It addresses common challenges developers face when defining object schemas, applying string and enum validations, handling optional and nullable fields, and ensuring safe input processing. By following these best practices, teams can prevent runtime errors, maintain consistent validation logic, and leverage TypeScript's type system effectively for robust applications.

The skill organizes 43 rules into eight prioritized categories, covering schema definition, parsing and validation, type inference, error handling, object schemas, schema composition, refinements and transforms, and performance optimization. Key features include guidance on using `safeParse` for input validation, distinguishing between `z.input` and `z.infer`, implementing custom error messages, and composing schemas with reusable modules or intersections. Each rule comes with a prefix and priority level to help developers quickly identify high-impact practices, and the guide emphasizes safe handling of JSON, early validation, and proper usage of Zod primitives and coercion techniques.

This skill is primarily targeted at TypeScript developers building applications that require strong runtime validation, including forms, APIs, and complex data structures. It is useful for both writing new schemas and reviewing existing Zod code for consistency and maintainability. Developers who need guidance on handling nested objects, discriminated unions, refinements, and transforms will find this skill particularly valuable. It is not intended for React Hook Form integration or OpenAPI client generation, as separate skills cover those areas.

FAQ

When should I use safeParse versus parse in Zod?

Use safeParse when handling user input to safely capture validation errors without throwing exceptions. Use parse when you want immediate exceptions on invalid data, typically in trusted contexts.

Can I use this skill with React Hook Form or OpenAPI clients?

No, this skill does not cover React Hook Form integration or OpenAPI client generation. For those use cases, refer to the dedicated react-hook-form or orval skills.

What are the main benefits of using z.infer over manual type definitions?

Using z.infer automatically derives TypeScript types from your Zod schemas, ensuring type safety and reducing the risk of mismatched types between your schema and your code.

Does this skill address performance considerations?

Yes, it includes a low-medium priority category for performance and bundle optimization, offering guidance on efficient validation and minimizing unnecessary computation.

Is this skill suitable for nested and complex object schemas?

Absolutely. It provides best practices for object schemas, discriminated unions, partial updates, and schema composition, making it suitable for complex and nested data structures.

All Files

49 files
AGENTS.md11.1 KB
View
SKILL.md5.3 KB
View
assets/templates/_template.md0.7 KB
View
references/error-path-for-nested.md3.6 KB
View
references/compose-preprocess.md3.6 KB
View
references/parse-handle-all-issues.md3.3 KB
View
metadata.json1.9 KB
View
references/error-avoid-throwing-in-refine.md3.4 KB
View
references/schema-use-enums.md2.7 KB
View
references/compose-pipe.md3.3 KB
View
references/object-discriminated-unions.md3.9 KB
View
references/object-extend-for-composition.md3.4 KB
View
references/error-custom-messages.md3.4 KB
View
references/parse-avoid-double-validation.md3.3 KB
View
references/schema-use-unknown-not-any.md2.2 KB
View
references/compose-lazy-recursive.md3.2 KB
View
references/parse-never-trust-json.md3.1 KB
View
references/refine-transform-coerce.md3.4 KB
View
references/_sections.md2.2 KB
View
references/schema-avoid-optional-abuse.md2.6 KB
View
references/type-export-schemas-and-types.md3.0 KB
View
README.md2.9 KB
View
references/error-i18n.md3.9 KB
View
references/type-use-z-infer.md3.0 KB
View
references/compose-shared-schemas.md3.2 KB
View
references/object-optional-vs-nullable.md3.6 KB
View
references/refine-defaults.md3.6 KB
View
references/compose-intersection.md3.4 KB
View
references/perf-avoid-dynamic-creation.md3.2 KB
View
references/type-enable-strict-mode.md2.9 KB
View
references/object-pick-omit.md3.8 KB
View
references/parse-use-safeparse.md2.7 KB
View
references/object-strict-vs-strip.md2.9 KB
View
references/refine-catch.md3.7 KB
View
references/object-partial-for-updates.md3.5 KB
View
references/perf-arrays.md3.9 KB
View
references/refine-add-path.md3.7 KB
View
references/error-use-flatten.md3.2 KB
View
references/perf-zod-mini.md3.0 KB
View
references/type-branded-types.md3.1 KB
View
references/parse-async-for-async-refinements.md3.0 KB
View
references/schema-coercion-for-form-data.md2.9 KB
View
references/schema-use-primitives-correctly.md2.1 KB
View
references/perf-lazy-loading.md3.5 KB
View
references/refine-vs-superrefine.md4.1 KB
View
references/perf-cache-schemas.md3.0 KB
View
references/schema-string-validations.md2.7 KB
View
references/parse-validate-early.md3.3 KB
View
references/type-input-vs-output.md3.1 KB
View

Install zod

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill