home / skills / oimiragieo / agent-studio / form-validation-with-zod

form-validation-with-zod skill

/.claude/skills/form-validation-with-zod

This skill enforces form validation with Zod across projects, reviewing code, suggesting improvements, and refactoring to ensure strong, type-safe validation.

npx playbooks add skill oimiragieo/agent-studio --skill form-validation-with-zod

Review the files below or copy the command above to add this skill to your agents.

Files (12)
SKILL.md
1.4 KB
---
name: form-validation-with-zod
description: Enforces the use of Zod for form validation throughout the project.
version: 1.0.0
model: sonnet
invoked_by: both
user_invocable: true
tools: [Read, Write, Edit]
globs: '**/*.ts'
best_practices:
  - Follow the guidelines consistently
  - Apply rules during code review
  - Use as reference when writing new code
error_handling: graceful
streaming: supported
---

# Form Validation With Zod Skill

<identity>
You are a coding standards expert specializing in form validation with zod.
You help developers write better code by applying established guidelines and best practices.
</identity>

<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>

<instructions>
When reviewing or writing code, apply these guidelines:

- Use Zod for form validation
  </instructions>

<examples>
Example usage:
```
User: "Review this code for form validation with zod compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>

## Memory Protocol (MANDATORY)

**Before starting:**

```bash
cat .claude/context/memory/learnings.md
```

**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

Overview

This skill enforces the use of Zod for form validation across a JavaScript project. I help teams identify missing or inconsistent validation, suggest Zod-based refactors, and provide clear, actionable guidance to standardize form validation patterns. The focus is practical: safer forms, consistent error handling, and predictable runtime behavior.

How this skill works

I scan form-related code paths and configuration to detect validators, validation libraries, and ad-hoc checks. I flag places that do not use Zod or that use mixed patterns, and I recommend concrete Zod schemas, type-safe bindings, and consistent error mapping. I can produce refactor examples, show how to derive TypeScript types from schemas, and explain why Zod patterns are preferred.

When to use it

  • When a project has multiple validation approaches or ad-hoc checks in components or API handlers
  • When you want a single source of truth for client and server validation
  • When migrating from runtime checks or other libraries to a schema-first approach
  • When you need to generate typed interfaces from validation logic
  • When you want consistent error shapes for forms and API responses

Best practices

  • Define reusable Zod schemas near domain models and import them into forms and handlers
  • Derive TypeScript types with z.infer for consistent compile-time types
  • Validate at the boundary: validate input server-side and revalidate client-side using the same schema
  • Map Zod errors to a uniform error shape for UI display and i18n
  • Keep schemas small and composed; prefer z.object + .extend over duplicating rules

Example use cases

  • Review a React form that uses manual checks and provide a Zod schema plus example resolver for React Hook Form
  • Refactor an Express route that performs ad-hoc validation into a middleware using Zod parsing and typed request handlers
  • Create shared schemas for signup and profile update flows so client and server share validation rules
  • Audit a codebase and produce a checklist of files to migrate to Zod with concrete migration steps

FAQ

Can Zod replace TypeScript types?

Zod complements TypeScript: you author Zod schemas and derive runtime-safe TypeScript types with z.infer, ensuring runtime validation and compile-time safety.

How do I map Zod errors to form fields?

Use z.safeParse or catch ZodError, then convert error.issues into a field-keyed object or your form library's error format for consistent UI display.