next-safe-action avatar

Safe Action Validation Errors

Guide for validation errors in next-safe-action, covering schema and manual field-level and form-level errors.

CCM score
66 of 100
skills.sh installs
1.2K
GitHub stars
1
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers two error sources: automatic schema validation and manual checks via returnValidationErrors() in server actions
  • Documents the default formatted shape with _errors arrays at each level, and the flattened fieldErrors and formErrors alternative
  • Explains that returnValidationErrors() always throws, so code paths after it never run
  • Designed for Next.js developers wiring server-action validation results into forms with Zod schemas

Install

$ npx -y skills add next-safe-action/skills --skill safe-action-validation-errors -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

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.

Details

Repository
github.com/next-safe-action/skills
Categories
Frontend & UI Code, Backend & APIs
First seen
May 16, 2026

More from next-safe-action/skills

All 8

Similar to Safe Action Validation Errors

More Frontend & UI Code