API Reference

Yup

Schema builder for value parsing and validation with a fluent, chainable API for forms and API payloads.

Official Documentation ↗
CompatibilityThis documentation covers version v1.4. Check the official docs for the latest API surface.

Installation

npmnpm install yup
pnpmpnpm add yup
yarnyarn add yup

Methods

Yup is a JavaScript schema builder for parsing and validating values. It lets you define schemas with a chainable API, then validate, cast, and transform input data with detailed errors.

Key Features

  • Chainable API: Compose validators like .min().max().required()
  • Casting: Coerce and strip input to match schema types
  • Conditional validation: .when() for dependent field rules
  • Error details: Structured ValidationError with paths and messages
  • Form integration: Pairs well with Formik and react-hook-form

Errors

The following points are quoted verbatim from the official documentation (https://github.com/jquense/yup). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

  • Schema also store a bunch of “metadata”, details about the schema itself, which can be used to improve error messages, build tools that dynamically consume schema, or serialize schema into another format. (https://github.com/jquense/yup)
  • In the case of a failing test, yup will throw a ValidationError with your (or the default) message for that test. (https://github.com/jquense/yup)
  • Error messages can also be constructed on the fly to customize how the schema fails. (https://github.com/jquense/yup)

FAQ

How does Yup compare to Zod?
Yup is runtime-only and requires manual TypeScript types, while Zod is TypeScript-first with automatic type inference. Yup is lighter and more mature for form libraries like Formik.
What does abortEarly do?
When false, Yup collects all validation errors instead of stopping at the first. This is useful for forms that want to show every field error at once rather than one at a time.
Can Yup validate nested and circular references?
Yes. Use yup.reach for nested paths and yup.object with lazy or yup.lazy for circular or self-referencing schemas that depend on their own value.