Skip to main content

27. Use Zod for Form Validation

Date: 2025-04-25

Status

Accepted

Context

To ensure that our application functions correctly and securely, we require form inputs to be validated before being accepted. Validating user input at the form level helps catch basic issues early, improves user experience, and reduces the chance of invalid data reaching deeper parts of the system.

Historically, we have used various libraries for client-side validation, including Yup. While Yup provided a powerful schema-based validation model, we encountered several challenges:

  • The API became increasingly complex to work with.
  • Some advanced use cases required verbose or unintuitive workarounds.
  • Yup development has slowed down significantly, and maintenance has been sporadic.

Decision

We will use Zod for all new form validation going forward.

Zod offers:

  • First-class TypeScript support with static type inference.
  • A clean and declarative API that is easy to read and maintain.
  • A growing and active developer community.
  • Better integration with modern React form libraries.

Given these advantages and the stagnation of Yup, Zod is a better long-term fit for our projects.

Consequences

  • Existing forms built with Yup may need to be migrated gradually to Zod.
  • New developers will need to familiarize themselves with Zod’s syntax and capabilities.
  • Documentation and internal tooling will be updated to align with Zod-based schemas.
  • We gain better developer ergonomics and maintainability for form validation.