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

Safe Action Validation Errors

  • 1k installs
  • Updated July 18, 2026
  • next-safe-action/skills

safe-action-validation-errors is a Claude Code skill that teaches developers to return structured, type-safe validation errors from Next.js server actions mapped to Zod schemas and React Hook Form fields.

About

safe-action-validation-errors is a Next.js server-action skill from next-safe-action/skills that shows how to use returnValidationErrors to emit field-level and form-level errors from Z.js actions with correct TypeScript inference. The workflow starts by passing the Zod input schema as the first argument so error shapes stay aligned with parsedInput types, then returning validation objects that React Hook Form can bind directly to inputs. Developers reach for safe-action-validation-errors when login, signup, or settings forms need server-side checks—duplicate email, weak password, business rules—without throwing exceptions or losing type safety. The skill assumes action files use the "use server" directive and actionClient.inputSchema patterns from next-safe-action.

  • Returns field-level validation errors matching your Zod schema shape
  • Supports multiple error messages per field
  • Enables combined form-level and field-level error messages
  • Works with nested object schemas for complex forms
  • Provides full TypeScript inference from your input schema

Safe Action Validation Errors by the numbers

  • 1,020 all-time installs (skills.sh)
  • +25 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #391 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/next-safe-action/skills --skill safe-action-validation-errors

Add your badge

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

Listed on Skillselion
Installs1k
Security audit3 / 3 scanners passed
Last updatedJuly 18, 2026
Repositorynext-safe-action/skills

How do Next.js server actions return typed form errors?

Return structured, type-safe validation errors from Next.js server actions that map directly to React Hook Form and Zod schemas.

Who is it for?

Next.js developers building server actions with Zod and React Hook Form who need structured, field-level error responses.

Skip if: Projects using REST APIs, tRPC, or client-only validation without next-safe-action server actions.

When should I use this skill?

User implements Next.js server actions with Zod and needs field-level validation errors for React Hook Form.

What you get

Type-safe validation error objects bound to React Hook Form fields and Zod schema keys

  • Server action handlers with returnValidationErrors
  • Field-mapped validation error responses

Files

SKILL.mdMarkdownGitHub ↗

next-safe-action Validation Errors

Two Sources of Validation Errors

1. Schema validation — automatic when input doesn't match .inputSchema() 2. Manual validation — via returnValidationErrors() in server code (e.g., "email already taken")

Both produce the same error structure on the client.

Default Error Shape (Formatted)

Mirrors the schema structure with _errors arrays at each level:

// For schema: z.object({ email: z.string().email(), address: z.object({ city: z.string() }) })
{
  _errors: ["Form-level error"],                    // root errors
  email: { _errors: ["Invalid email address"] },    // field errors
  address: {
    _errors: ["Address section error"],
    city: { _errors: ["City is required"] },        // nested field errors
  },
}

returnValidationErrors

Throws a ActionServerValidationError that the framework catches and returns as result.validationErrors. It never returns — it always throws.

"use server";

import { z } from "zod";
import { returnValidationErrors } from "next-safe-action";
import { actionClient } from "@/lib/safe-action";

const registerSchema = z.object({
  email: z.string().email(),
  username: z.string().min(3),
});

export const register = actionClient
  .inputSchema(registerSchema)
  .action(async ({ parsedInput }) => {
    // Check business rules after schema validation passes
    const existingUser = await db.user.findByEmail(parsedInput.email);
    if (existingUser) {
      returnValidationErrors(registerSchema, {
        email: { _errors: ["This email is already registered"] },
      });
    }

    const existingUsername = await db.user.findByUsername(parsedInput.username);
    if (existingUsername) {
      returnValidationErrors(registerSchema, {
        username: { _errors: ["This username is taken"] },
      });
    }

    // Both checks passed — create the user
    const user = await db.user.create(parsedInput);
    return { id: user.id };
  });

Root-Level Errors

Use _errors at the top level for form-wide errors:

returnValidationErrors(schema, {
  _errors: ["You can only create 5 posts per day"],
});

Supporting Docs

  • Custom validation errors and returnValidationErrors patterns
  • Formatted vs flattened shapes, per-action override

Displaying Validation Errors

// Formatted shape (default)
{result.validationErrors?.email?._errors?.map((error) => (
  <p key={error} className="text-red-500">{error}</p>
))}

// Root-level errors
{result.validationErrors?._errors?.map((error) => (
  <p key={error} className="text-red-500">{error}</p>
))}
// Flattened shape
{result.validationErrors?.fieldErrors?.email?.map((error) => (
  <p key={error} className="text-red-500">{error}</p>
))}

// Form-level errors (flattened)
{result.validationErrors?.formErrors?.map((error) => (
  <p key={error} className="text-red-500">{error}</p>
))}

Related skills

How it compares

Pick this over generic Zod error-handling guides when the stack already uses next-safe-action actionClient and React Hook Form together.

FAQ

How does returnValidationErrors work in next-safe-action?

safe-action-validation-errors documents returnValidationErrors, which takes the Zod input schema first for type inference and a second argument matching the schema shape. Server actions return these objects instead of throwing, letting React Hook Form display field-level messages

Can Next.js server actions return field-specific form errors?

safe-action-validation-errors shows field-level and form-level error objects from next-safe-action actions. Errors align with Zod schema keys so React Hook Form can bind them directly to inputs without manual mapping.

Backend & APIsbackendintegrations

This week in AI coding

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

unsubscribe anytime.