zod-validation-expert

Builds type-safe Zod validation schemas for TypeScript applications and framework integrations.

1|Updated Aug 17, 2025
One-click install
npx skills add https://github.com/ratnesh-maurya/mdconverter --skill zod-validation-expert-ratnesh-maurya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod-validation-expert
Source: https://github.com/ratnesh-maurya/mdconverter/tree/main/.claude/skills/zod-validation-expert
Command: npx skills add https://github.com/ratnesh-maurya/mdconverter --skill zod-validation-expert-ratnesh-maurya

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing runtime validation logic and TypeScript types separately leads to duplication and drift. This Skill helps you define a single Zod schema that provides both runtime parsing and static type inference, with correct patterns for forms, APIs, and environment variables. ## Core Features & Use Cases - Schema Definition & Type Inference: Define primitives, objects, arrays, records, unions, and discriminated unions, then derive TypeScript types with z.infer. - Advanced Validation: Apply custom error messages, .refine / .superRefine cross-field checks, transformations, and coercion for FormData and URL query inputs. - Framework Integration: Wire schemas into React Hook Form via zodResolver, Next.js Server Actions with safeParse, and fail-fast environment variable validation. - Use Case: When building a Next.js form, generate a schema with coercion for checkbox values, validate FormData in a Server Action, and return flattened field errors to the UI. ## Quick Start Ask the assistant to create a Zod schema with type inference and React Hook Form integration for your form or API input.

Frequently Asked Questions about zod-validation-expert

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

FAQPage Schema
How do I validate form data with Zod and React Hook Form?

Define a Zod schema, infer its type with z.infer, and pass it to useForm via zodResolver from @hookform/resolvers/zod. Validation errors then map automatically to formState.errors for display next to each input.

What is the difference between Zod parse and safeParse?

parse throws a ZodError on invalid input and requires try/catch, while safeParse returns a result object with a success flag. safeParse is preferred because TypeScript narrows the result type, enabling clean error handling without exceptions.

How do I validate environment variables with Zod?

Define a schema describing each variable, using z.coerce.number() for ports and z.enum for NODE_ENV, then call schema.parse(process.env) at startup. The app fails immediately if any variable is missing or invalid, and the result is fully typed.

Why does Zod optional still reject empty strings?

The .optional() modifier permits undefined, not empty strings. To treat an empty string as absent, use .or(z.literal("")) or preprocess with a transform that converts empty strings to undefined before validation.

How do I validate that two password fields match in Zod?

Use .refine on the object schema comparing data.password and data.confirmPassword, and set the path option to ["confirmPassword"]. Without the path option, the error will not attach to the correct form field.

How do I fix Type instantiation is excessively deep in Zod?

This error occurs with deeply recursive schemas. Use z.lazy(() => NodeSchema) for self-referential structures and define the recursive TypeScript type explicitly instead of relying solely on z.infer.