What is it?
Standard Schema is a standard interface designed to be implemented by all JavaScript and TypeScript schema libraries.
The goal is to make it easier for other frameworks and libraries to accept user-defined schemas, without needing to implement a custom adapter for each schema library. Because Standard Schema is aspecification, they can do so with no additional runtime dependencies.
The specification
The specification has a few primary design goals.
- Support runtime validation. Given a Standard Schema compatible validator, you should be able to validate data with it (duh). Validation errors should be presented a standardized format.
- Support static type inference. For TypeScript libraries that do type inference, the specification provides a standard way for them to "advertise" their inferred type, so it can be inferred by external tools. compatible validator should "expose" an inferred type that can be should be able to infer an validate data with it (duh).
- Easy to implement. It should be simple for schema libraries to implement, ideally only requiring a few lines of code.
- Do no harm to DX. The specification must avoid conflicts with the existing API surfaces of all existing libraries. It should be minimal to avoid unnecessary clutter in Intellisense/autocompletion.
Below is a simplified version of the specification designed for digestibility. The complete spec can be found in the repository.
interface StandardSchemaV1<Input = unknown, Output = Input> {
"~standard": {
// version of Standard Schema being implemented
version: 1;
// the name of the validation library
vendor: string;
// validator function
validate: (
value: unknown,
) => Result<Output> | Promise<Result<Output>>;
// inferred types
types?: { input: Input, output: Output } | undefined;
};
}
type Result<Output> =
| { value: Output; issues?: undefined }
| { issues: Array<{
message: string;
path?: ReadonlyArray<PropertyKey | PathSegment>
}>
}
The entire spec is tucked into a ~standard
property.
What libraries implement the spec?
The following validation libraries have implemented the Standard Schema specification.
If you maintain a schema library that has implemented Standard Schema, please open a PR to add it to this list. If you have questions about implementation, reach out on GitHub or contact
Implementer | Version(s) | Docs |
---|---|---|
Zod | 3.24.0+ | zod.dev |
Valibot | v1.0 (including RCs) | valibot.dev |
ArkType | v2.0+ | arktype.io |
Arri Schema | v0.71.0+ | github.com/modiimedia/arri |
How do I accept Standard Schemas in my framework / library?
Let's run through a simple example of how to write a generic function that accepts any Standard Schema-compliant validator, extracts its inferred type, and uses it to validate data.
import type { StandardSchemaV1 } from "@standard-schema/spec";
export async function standardValidate<T extends StandardSchemaV1>(
schema: T,
input: StandardSchemaV1.InferInput<T>,
): Promise<StandardSchemaV1.InferOutput<T>> {
let result = schema["~standard"].validate(input);
if (result instanceof Promise) result = await result;
// if the `issues` field exists, the validation failed
if (result.issues) {
throw new Error(JSON.stringify(result.issues, null, 2));
}
return result.value;
}
This simple function can be used to accept any standard-compliant schema and use it to parse data in a type-safe way.
import * as z from "zod";
import * as v from "valibot";
import { type } from "arktype";
const zodResult = await standardValidate(z.string(), "hello");
// => "hello"
const valibotResult = await standardValidate(v.string(), "hello");
// => "hello"
const arktypeResult = await standardValidate(type("string"), "hello");
// => "hello"
What tools accept Standard Schema-compliant schemas?
The following frameworks and libraries have added support for any schema that conform to the Standard Schema specification.
Integrator | Description |
---|---|
tRPC | 🧙♀️ Move fast and break nothing. End-to-end typesafe APIs made easy |
TanStack Form | 🤖 Headless, performant, and type-safe form state management for TS/JS, React, Vue, Angular, Solid, and Lit |
TanStack Router | A fully type-safe React router with built-in data fetching, stale-while revalidate caching and first-class search-param APIs |
UploadThing | File uploads for modern web devs |
Formwerk | A Vue.js Framework for building high-quality, accessible, delightful forms. |
GQLoom | Weave GraphQL schema and resolvers using Standard Schema |
Nuxt UI | A UI Library for modern web apps, powered by Vue & Tailwind CSS |
oRPC | Typesafe APIs made simple 🪄 |
Regle | Type-safe model-based form validation library for Vue.js |
If you've implemented Standard Schema in your library, please open a PR to add it to this list.
Who wrote the spec?
The original concept was proposed on Twitter by Colin McDonnell (creator of Zod). The final version of the spec was designed by Colin, Fabian Hiller (creator of Valibot), and David Blass (creator of ArkType).
What's next?
The 1.0.0
version of @standard-schema/spec
has been published to npm and JSR. With any luck, this will be the only version ever published.
- If you want to dig into the spec, it's defined as a single TypeScript file, available on GitHub in the repository.
- For validation library authors, refer to the README for more a more comprehensive integration guide & FAQs.
- For other maintainers who are interested in integrating with Standard Schema compatible libraries, refer to the README or refer to other implementations like Tanstack Form or Hono Middleware.