next-safe-action avatar

Safe Action Validation Errors

If you're using next-safe-action and need to handle validation errors beyond schema checks, this covers the patterns. It explains returnValidationErrors for business logic failures like "email already taken" and how those errors match the same structure as schema validation errors. The formatted shape mirrors your Zod schema with _errors arrays at each level, while the flattened shape separates fieldErrors and formErrors. Useful for knowing when to throw validation errors in server code versus letting schema validation catch malformed input. The display examples show exactly how to render field-level and form-level errors in either shape.

skills.sh installs
1.2K
GitHub stars
1
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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.

Sponsors

Details

Repository
github.com/next-safe-action/skills
Category
Debugging
First seen
May 16, 2026

More from next-safe-action/skills

All 9

Recommended

More Debugging
1am-will avatarcontext7am-will/codex-skillsFetch up-to-date library documentation via Context7 CLI. Use PROACTIVELY when: (1) Working with ANY external library (React, Next.js, Supabase, etc.) (2) User a1.2Kskills.sh installs
2sergiodxa avatarfrontend-react-best-practicessergiodxa/agent-skillsReact performance optimization guidelines. Use when writing, reviewing, or refactoring React components to ensure optimal rendering and bundle patterns. Trigger1.2Kskills.sh installs
3next-safe-action avatarsafe-action-middlewarenext-safe-action/skillsUse when implementing middleware for next-safe-action -- authentication, authorization, logging, rate limiting, error interception, context extension, or creati1.2Kskills.sh installs
4dbt-labs avatarusing-dbt-for-analytics-engineeringdbt-labs/dbt-agent-skillsBuilds and modifies dbt models, writes SQL transformations using ref() and source(), creates tests, and validates results with dbt show. Use when doing any dbt 1.2Kskills.sh installs
5nexscope-ai avataramazon-buy-boxnexscope-ai/amazon-skillsAmazon Buy Box strategy and optimization framework. Eligibility factor analysis, competitive pricing strategies, FBA vs FBM impact assessment, seller performanc1.2Kskills.sh installs
6pproenca avatarnextjspproenca/dot-skillsNext.js 16 App Router performance, caching, server components, server actions, routing, and codebase-hygiene best practices — plus a category-major review/refac1.2Kskills.sh installs