Technical document

Pitfalls when sharing form validation with Zod

We will organize how to handle sharing scope, transformations, error messages, and version differences when using Zod schemas for React forms and API input validation.
Frontend / Input Validation~10 minPublication Date September 22, 2026Update date September 22, 2026
Pitfalls when sharing form validation with Zod

Summary

Key points of this document

  • Where are the design challenges?
  • How to define boundaries
  • Details that matter in implementation

Overview

Zod is a convenient tool that allows sharing the same validation between frontend and backend. However, it's not always correct to use the exact same schema as is. While sharing schemas with Zod is useful, data in the middle of form input and confirmed API data are not of the same type.

Where are the design challenges?

Forms temporarily hold unentered, partially entered, or invalid strings. On the other hand, APIs want to receive confirmed types. Using the same Zod schema for both can make it difficult to handle intermediate input states.

Browser input values are fundamentally strings. Numbers, dates, checkboxes, multiple selections, etc., require conversion. Furthermore, a design that doesn't re-validate on the API side, even if validation passed on the frontend, is not safe.

Sharing form validation with Zod can reduce duplication. However, forms handle empty strings, unselected options, and incomplete values during input. If you use only the API-side save schema as is, the input experience will become rigid.

How to define boundaries

Consider separating schemas for form state, submission, and API reception. Common elements should be limited to item names and basic constraints, while screen-specific intermediate input states and display messages are handled on the frontend.

In design, we separate form schema, normalized schema, and API schema. The React side allows for a loose state during input, normalizes it upon submission, and passes it to the API schema. The API side does not trust it and re-validates.

Details that matter in implementation

In Zod, you can use preprocess and transform, but mixing conversion and validation too much can reduce clarity. First, normalize the input string, then validate business rules. On the API, re-confirm the same constraints upon reception.

In implementation, organize functions that normalize empty values for dates, numbers, checkboxes, and selects either outside the schema or as preprocess. Server errors should include a field path so that form libraries can map them to display positions.

  • Decide for each item whether an empty string should be undefined, null, or 0.
  • Avoid putting too many business rules in Zod's refine; perform validations requiring DB reference on the API side.
  • Error messages should be phrased in terms that users can understand and correct, not based on schema convenience.

Observe how it breaks

During validation, check for empty strings, full-width numbers, date formats, boundary values, empty arrays, and unnecessary fields. Also, check if error messages are phrased per item in a way that users can correct.

During validation, separately check for states during input, before submission, API rejection, and server error reflection. Practicality increases not only by ensuring types pass but also by testing which errors appear for which items on the screen.

Discarded options and tradeoffs

Separating schemas increases duplication. Aiming for complete sharing makes the screen state rigid. It is practical to separate constraints that should be shared from those specific to the screen or API.

Thorough schema sharing reduces duplication, but it becomes difficult to express the input experience for each screen. Instead of complete sharing, it's easier to handle by deriving screen-specific and API-specific schemas from a common base schema.

Decision criteria to leave for the team

The value of Zod is not to put everything into a single schema. By separating validation, mindful of each stage—during input, submission, and saving—you can achieve both type safety and usability.

The purpose of Zod sharing is not to use the same schema everywhere. Clearly defining the boundary between input and saving, and separating normalization and validation, leads to more robust forms.

Technical documents

We will continue to increase technical documentation.

We will continue to organize our thoughts on AI, cloud, business app development, requirements definition, and operational design into documents.

Go to technical documentation list