Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
giuseppe-trisciuoglio avatar

Zod Validation Utilities

  • 1.5k installs
  • 311 repo stars
  • Updated June 22, 2026
  • giuseppe-trisciuoglio/developer-kit

zod-validation-utilities is an agent skill for reusable Zod v4 schemas validating API payloads, forms, and config in TypeScript.

About

The zod-validation-utilities skill provides production-ready Zod v4 patterns for reusable type-safe validation with minimal boilerplate. It covers modern APIs like z.uuid, z.email, z.url with error option, z.coerce for boundary parsing, preprocess and transform pipelines, cross-field refine and superRefine invariants, and safeParse workflow at handler boundaries exporting z.input and z.output types. Utility schemas include pagination query coercion, normalized email, and shared ID types. React Hook Form integration uses zodResolver. Workflow defines schema at boundary, safeParse, branch on success, use result.data with inference, return formatted errors. Use when designing validation layers, parsing z.object schemas, or runtime type-safe TypeScript validation.

  • Zod v4 modern APIs: z.uuid, z.email, z.url with error option.
  • Boundary coercion with z.coerce and preprocess transforms.
  • safeParse workflow: define, parse, branch, use result.data.
  • Export z.input and z.output inferred types from schemas.
  • React Hook Form integration via zodResolver.

Zod Validation Utilities by the numbers

  • 1,539 all-time installs (skills.sh)
  • +79 installs in the week ending Jul 28, 2026 (Skillselion tracking)
  • Ranked #314 of 4,386 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 28, 2026 (Skillselion catalog sync)
At a glance

zod-validation-utilities capabilities & compatibility

Capabilities
zod v4 primitive schemas · coercion and transform pipelines · safeparse boundary workflow · shared utility schema library
Use cases
api development · frontend
From the docs

What zod-validation-utilities says it does

Production-ready Zod v4 patterns for reusable, type-safe validation with minimal boilerplate.
SKILL.md
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill zod-validation-utilities

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1.5k
repo stars311
Security audit3 / 3 scanners passed
Last updatedJune 22, 2026
Repositorygiuseppe-trisciuoglio/developer-kit

How do I design type-safe Zod v4 validation with coercion and safeParse at API boundaries?

Create reusable Zod v4 schemas for API payloads, forms, and config with type-safe validation.

Who is it for?

TypeScript developers building validation layers for APIs, forms, env vars, or external input.

Skip if: Skip for non-TypeScript runtimes or JSON Schema without Zod integration needs.

When should I use this skill?

User designs validation layers, z.object schemas, z.email, or runtime type-safe parsing.

What you get

Reusable Zod schemas with inferred input/output types and consistent safeParse error handling.

  • Zod v4 schema module
  • inferred TypeScript types

By the numbers

  • EventSchema example defines 3 discriminated union variants: user_created, user_deleted, subscription_upgraded
  • Plan enums cover 3 tiers: free, pro, enterprise

Files

SKILL.mdMarkdownGitHub ↗

Zod Validation Utilities

Overview

Production-ready Zod v4 patterns for reusable, type-safe validation with minimal boilerplate. Focuses on modern APIs, predictable error handling, and form integration.

When to Use

  • Defining request/response validation schemas in TypeScript services
  • Parsing untrusted input from APIs, forms, env vars, or external systems
  • Standardizing coercion, transforms, and cross-field validation
  • Building reusable schema utilities across teams
  • Integrating React Hook Form with Zod using zodResolver

Instructions

1. Start with strict object schemas and explicit field constraints 2. Prefer modern Zod v4 APIs and the error option for error messages 3. Use coercion at boundaries (z.coerce.*) when input types are uncertain 4. Keep business invariants in refine/superRefine close to schema definitions 5. Export both schema and inferred types (z.input/z.output) for consistency 6. Reuse utility schemas (email, id, dates, pagination) to reduce duplication

Validation Workflow

When integrating validation into an API handler or service:

1. Define the schema at the boundary (handler, queue, config loader) 2. Parse with safeParse to handle errors gracefully 3. Check result.success to branch on failure/success 4. Use result.data with full type inference in success path 5. Return formatted errors or proceed with validated data

See example 7 (safeParse workflow) for the complete pattern.

Examples

1) Modern Zod 4 primitives and object errors

import { z } from "zod";

export const UserIdSchema = z.uuid({ error: "Invalid user id" });
export const EmailSchema = z.email({ error: "Invalid email" });
export const WebsiteSchema = z.url({ error: "Invalid URL" });

export const UserProfileSchema = z.object(
  {
    id: UserIdSchema,
    email: EmailSchema,
    website: WebsiteSchema.optional(),
  },
  { error: "Invalid user profile payload" }
);

2) Coercion, preprocess, and transform

import { z } from "zod";

export const PaginationQuerySchema = z.object({
  page: z.coerce.number().int().min(1).default(1),
  pageSize: z.coerce.number().int().min(1).max(100).default(20),
  includeArchived: z.coerce.boolean().default(false),
});

export const DateFromUnknownSchema = z.preprocess(
  (value) => (typeof value === "string" || value instanceof Date ? value : undefined),
  z.coerce.date({ error: "Invalid date" })
);

export const NormalizedEmailSchema = z
  .string()
  .trim()
  .toLowerCase()
  .email({ error: "Invalid email" })
  .transform((value) => value as Lowercase<string>);

3) Complex schema structures

import { z } from "zod";

const TagSchema = z.string().trim().min(1).max(40);

export const ProductSchema = z.object({
  sku: z.string().min(3).max(24),
  tags: z.array(TagSchema).max(15),
  attributes: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])),
  dimensions: z.tuple([z.number().positive(), z.number().positive(), z.number().positive()]),
});

export const PaymentMethodSchema = z.discriminatedUnion("type", [
  z.object({ type: z.literal("card"), last4: z.string().regex(/^\d{4}$/) }),
  z.object({ type: z.literal("paypal"), email: z.email() }),
  z.object({ type: z.literal("wire"), iban: z.string().min(10) }),
]);

4) refine and superRefine

import { z } from "zod";

export const PasswordSchema = z
  .string()
  .min(12)
  .refine((v) => /[A-Z]/.test(v), { error: "Must include an uppercase letter" })
  .refine((v) => /\d/.test(v), { error: "Must include a number" });

export const RegisterSchema = z
  .object({
    email: z.email(),
    password: PasswordSchema,
    confirmPassword: z.string(),
  })
  .superRefine((data, ctx) => {
    if (data.password !== data.confirmPassword) {
      ctx.addIssue({
        code: "custom",
        path: ["confirmPassword"],
        message: "Passwords do not match",
      });
    }
  });

5) Optional, nullable, nullish, and default

import { z } from "zod";

export const UserPreferencesSchema = z.object({
  nickname: z.string().min(2).optional(),      // undefined allowed
  bio: z.string().max(280).nullable(),         // null allowed
  avatarUrl: z.url().nullish(),                // null or undefined allowed
  locale: z.string().default("en"),           // fallback when missing
});

6) React Hook Form integration (zodResolver)

import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";

const ProfileFormSchema = z.object({
  name: z.string().min(2, { error: "Name too short" }),
  email: z.email({ error: "Invalid email" }),
  age: z.coerce.number().int().min(18),
});

type ProfileFormInput = z.input<typeof ProfileFormSchema>;
type ProfileFormOutput = z.output<typeof ProfileFormSchema>;

const form = useForm<ProfileFormInput, unknown, ProfileFormOutput>({
  resolver: zodResolver(ProfileFormSchema),
  criteriaMode: "all",
});

7) Error handling workflow with safeParse

import { z } from "zod";
import type { ZodError } from "zod";

const ResultSchema = z.object({ id: z.string(), name: z.string() });

function parseAndHandle(input: unknown) {
  const result = ResultSchema.safeParse(input);

  if (!result.success) {
    const error = result.error as ZodError;
    console.error("Validation failed:", error.errors);
    return { success: false as const, error: error.format() };
  }

  return { success: true as const, data: result.data };
}
Tip: For advanced discriminated union patterns and complex React Hook Form workflows, see references/advanced-patterns.md.

Best Practices

  • Keep schemas near boundaries (HTTP handlers, queues, config loaders)
  • Prefer safeParse for recoverable flows; parse for fail-fast execution
  • Share small schema utilities (id, email, slug) to enforce consistency
  • Use z.input and z.output when transforms/coercions change runtime shape
  • Avoid overusing preprocess; prefer explicit z.coerce.* where possible
  • Treat external payloads as untrusted and always validate before use

Constraints and Warnings

  • Ensure examples match your installed zod major version (v4 APIs shown)
  • error is the preferred option for custom errors in Zod v4 patterns
  • Discriminated unions require a stable discriminator key across variants
  • Coercion can hide bad upstream data; add bounds and refinements defensively

Related skills

Forks & variants (1)

Zod Validation Utilities has 1 known copy in the catalog totaling 3 installs. They canonicalize to this original listing.

How it compares

Pick zod-validation-utilities over basic Zod docs when discriminated unions, recursion, or Map/Set validation are required in production schemas.

FAQ

Zod v4 API changes?

Use z.uuid, z.email, z.url with error option and z.coerce at uncertain input boundaries.

Parse or safeParse?

Use safeParse at boundaries to branch on result.success and handle errors gracefully.

Is zod-validation-utilities safe to install?

Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.