api-contracts-and-zod-validation
Generate Zod schemas and TypeScript types for forms, API routes, and Server Actions with runtime validation. Use this skill when creating API contracts, validating request/response payloads, generating form schemas, adding input validation to Server Actions or route handlers, or ensuring type safety across client-server boundaries. Trigger terms include zod, schema, validation, API contract, form validation, type inference, runtime validation, parse, safeParse, input validation, request validation, Server Action validation.
Best use case
api-contracts-and-zod-validation is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Generate Zod schemas and TypeScript types for forms, API routes, and Server Actions with runtime validation. Use this skill when creating API contracts, validating request/response payloads, generating form schemas, adding input validation to Server Actions or route handlers, or ensuring type safety across client-server boundaries. Trigger terms include zod, schema, validation, API contract, form validation, type inference, runtime validation, parse, safeParse, input validation, request validation, Server Action validation.
Teams using api-contracts-and-zod-validation should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/api-contracts-and-zod-validation/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How api-contracts-and-zod-validation Compares
| Feature / Agent | api-contracts-and-zod-validation | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Generate Zod schemas and TypeScript types for forms, API routes, and Server Actions with runtime validation. Use this skill when creating API contracts, validating request/response payloads, generating form schemas, adding input validation to Server Actions or route handlers, or ensuring type safety across client-server boundaries. Trigger terms include zod, schema, validation, API contract, form validation, type inference, runtime validation, parse, safeParse, input validation, request validation, Server Action validation.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# API Contracts and Zod Validation Generate Zod schemas with TypeScript type inference for forms, API routes, and Server Actions. Validate inputs in Server Actions or route handlers with runtime type checking. ## Core Capabilities ### 1. Generate Zod Schemas from TypeScript Types When creating API contracts or form validations: - Analyze existing TypeScript interfaces or types - Generate equivalent Zod schemas with proper validation rules - Ensure bidirectional type compatibility (Zod -> TypeScript) - Use `z.infer<typeof schema>` for automatic type inference ### 2. Form Validation Schemas To create form validation with Zod: - Generate schemas for React Hook Form, Formik, or native forms - Include field-level validation rules (min/max length, regex, custom validators) - Support nested objects, arrays, and complex data structures - Provide helpful error messages for validation failures - Use `references/zod_patterns.md` for common validation patterns ### 3. API Route and Server Action Validation To add validation to API endpoints or Server Actions: - Wrap handler logic with schema validation using `.parse()` or `.safeParse()` - Return typed errors for validation failures - Generate request/response schemas for API contracts - Validate query parameters, body payloads, and route parameters - Ensure type safety between client and server code ### 4. Schema Generation Script Use `scripts/generate_zod_schema.py` to automate schema generation: ```bash python scripts/generate_zod_schema.py --input types/entities.ts --output schemas/entities.ts ``` The script: - Parses TypeScript interfaces/types - Generates Zod schemas with appropriate validators - Preserves JSDoc comments as descriptions - Handles common patterns (optional fields, unions, enums) ## Resource Files ### scripts/generate_zod_schema.py Automated TypeScript-to-Zod schema generator. Parses TypeScript AST and generates equivalent Zod schemas. ### references/zod_patterns.md Common Zod validation patterns including: - String validation (email, URL, UUID, custom regex) - Number constraints (min, max, positive, integer) - Date validation and transformation - Array and tuple validation - Object shape validation - Union and discriminated unions - Optional and nullable fields - Custom refinements and transforms - Error message customization ### assets/schema_templates/ Pre-built Zod schema templates: - `form_schema_template.ts` - Basic form validation - `api_route_schema_template.ts` - API route request/response - `server_action_schema_template.ts` - Server Action input/output - `entity_schema_template.ts` - Database entity validation ## Usage Workflow ### For New API Routes 1. Define request/response TypeScript types 2. Generate Zod schemas using `scripts/generate_zod_schema.py` or templates 3. Add validation middleware to route handler 4. Return typed validation errors on failure ### For Server Actions 1. Define input parameters as TypeScript types 2. Create Zod schema for validation 3. Use `.safeParse()` at the beginning of the action 4. Return validation errors in action result 5. Handle errors on the client side ### For Forms 1. Define form fields as TypeScript interface 2. Generate Zod schema with field validators 3. Integrate with form library (React Hook Form recommended) 4. Display validation errors inline ## Best Practices - Always use `.safeParse()` instead of `.parse()` to avoid throwing exceptions - Provide clear, user-friendly error messages - Validate early (at API boundary or Server Action entry) - Keep schemas colocated with routes/actions for maintainability - Use `z.infer<typeof schema>` for automatic TypeScript types - Document validation rules in schema comments - Test edge cases (empty values, invalid formats, boundary conditions) ## Integration with Worldbuilding App Common use cases for worldbuilding applications: - **Entity creation forms**: Validate character, location, faction data - **Relationship APIs**: Ensure valid entity IDs and relationship types - **Timeline events**: Validate dates, ordering, and event data - **Search/filter endpoints**: Validate query parameters and filters - **Bulk operations**: Validate arrays of entities or updates - **Import/export**: Validate file formats and data structure Consult `references/zod_patterns.md` for specific validation patterns applicable to worldbuilding entities.
Related Skills
bio-alignment-validation
Validate alignment quality with insert size distribution, proper pairing rates, GC bias, strand balance, and other post-alignment metrics. Use when verifying alignment data quality before variant calling or quantification.
date-validation
Use when editing Planning Hubs, timelines, calendars, or any file with day-name + date combinations (Wed Nov 12), relative dates (tomorrow), or countdowns (18 days until) - validates day-of-week accuracy, relative date calculations, and countdown math with two-source ground truth verification before allowing edits
spring-validation
Bean Validation (Jakarta Validation) with Spring Boot. Custom validators, validation groups, cross-field validation, and internationalized error messages.
Smart Contracts
Smart contracts are self-executing programs on blockchain. This guide covers Solidity basics, contract deployment, interaction, and frontend integration for building decentralized applications with au
fullstack-validation
Comprehensive validation methodology for multi-component applications including backend, frontend, database, and infrastructure
Data Contracts
A Data Contract is a formal agreement between a data producer (e.g., a microservice) and a data consumer (e.g., a data platform) that defines the structure, semantics, and quality of data being shared
api-validation
Apply when validating API request inputs: body, query params, path params, and headers. This skill covers Zod v4 patterns.
api-request-validation
A skill for implementing robust API request validation in Python web frameworks like FastAPI using Pydantic. Covers Pydantic models, custom validators (email, password), field-level and cross-field validation, query/file validation, and structured error responses. Use when you need to validate incoming API requests.
API Contracts Generator
Génère des contrats API cohérents entre Frontend (Next.js) et Backend (NestJS) avec types synchronisés, validation standardisée et error handling uniforme. À utiliser lors de la création d'APIs, DTOs, types frontend/backend, ou quand l'utilisateur mentionne "API", "DTO", "types", "contract", "validation", "frontend-backend", "synchronisation".
api-contracts-and-validation
Define and validate API contracts using Zod
api-contract-validation
Detect breaking changes in API contracts (OpenAPI/Swagger specs)
android-playstore-api-validation
Create and run validation script to test Play Store API connection