explaingit

open-circle/valibot

8,636TypeScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A tiny TypeScript library for validating data at runtime that can be up to 95% smaller in a production bundle than alternatives like Zod, because you only ship the validation functions you actually import.

Mindmap

mindmap
  root((Valibot))
    What it does
      Runtime validation
      Schema definition
      Type inference
    Key feature
      Tree-shakeable API
      Tiny bundle size
      No dependencies
    API
      parse throws
      safeParse returns result
      Composable functions
    Audience
      TypeScript developers
      Frontend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Validate incoming API response data against a schema before using it in your app, with TypeScript types inferred automatically from the same schema.

USE CASE 2

Check user-submitted form data against rules like required email format and minimum password length, and get structured error messages when validation fails.

USE CASE 3

Replace Zod with Valibot in a frontend bundle where file size is a concern, keeping the same schema-first workflow at a fraction of the weight.

Tech stack

TypeScriptJavaScript

Getting it running

Difficulty · easy Time to first run · 5min

No external dependencies, install from npm and import only the functions you need.

MIT licensed, use freely for any purpose, including commercial projects, with no restrictions beyond keeping the copyright notice.

In plain English

Valibot is a TypeScript library that checks whether data matches a shape you define. You describe the expected structure once, as a schema, and Valibot runs that schema against real data at runtime to confirm it matches. This covers incoming server data, form inputs, configuration files, or anything else your code receives from outside sources. The main practical difference between Valibot and similar tools is how small it stays in a production build. Its API is built from many small, single-purpose functions rather than a few large ones. A bundler can detect which functions you actually import and drop the rest. The README states this can reduce bundle size by up to 95% compared to Zod, a widely used alternative, with a minimal use case starting at under 700 bytes. You define a schema by composing those functions. The README shows a login example: an object schema that requires a valid email string and a password of at least 8 characters. TypeScript infers the correct output type directly from the schema definition, so you write the shape once and get both runtime validation and compile-time type safety from a single source. For running a schema against data, you can use parse, which throws an error when data fails, or safeParse, which returns a result object instead of throwing. The library runs in any JavaScript environment, has no external dependencies, and is fully covered by unit tests. It is MIT licensed and was originally created as a bachelor thesis at Stuttgart Media University.

Copy-paste prompts

Prompt 1
Using Valibot, write me a TypeScript schema for a login form that requires a valid email address and a password of at least 8 characters, and show me how to run safeParse on submitted form data.
Prompt 2
Show me how to define a Valibot schema for an API response object that has a required string id, an optional number count, and an array of string tags.
Prompt 3
I want to validate environment variables at startup using Valibot. Write me a schema that checks NODE_ENV is one of development, staging, or production, and throws a clear error if it is not.
Prompt 4
How do I get TypeScript to infer the output type of a Valibot schema so I do not have to write a separate type definition?
Prompt 5
Show me how to use Valibot's pipe function to add a custom validation rule on top of a string field, for example checking that a username contains no spaces.
Open on GitHub → Explain another repo

← open-circle on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.