validonce
Write cross-field validation rules once, on the server, and enforce the same rules in the browser.
The problem
Field rules such as types, lengths and patterns already travel from a backend’s OpenAPI document to the frontend. Rules that involve more than one field don’t: “company is required when the plan is Pro”, “the end date must be on or after the start date”. Teams write those twice, once in the backend and once in the form, and the two copies drift apart.
validonce exports those rules from your backend (ASP.NET Core, FastAPI, Fastify, NestJS, Go or Spring Boot, or the CEL rules of a Kubernetes CRD) as data in your OpenAPI document. A small runtime applies them in the browser, so React, Angular, Vue and plain HTML forms check the same rules and show each error on the right field.
The playground lets you pick any backend and frontend and watch it work, including the server’s 422 landing on the same fields.
How it works
RequiredWhen · Compare__rules__ = [ when(…).require(…) ]validonce/rulesstruct rulesBean Validationx-kubernetes-validationscomponents.schemas.Signup"x-validonce": [ … ]
Five rule kinds, one format
withRules(zod)React (react-hook-form)
Angular (Signal / Reactive Forms)
Vue (VeeValidate)
Web components (
validonce/dom)every request; a broken rule returns 422
The server always enforces the rules. The browser runs them first, for fast feedback. If the browser is skipped or out of date, the server’s 422 response uses the same issue shape, and the client maps each error back onto its form field.
Migrate with an agent
Already have cross-field checks in FluentValidation, Pydantic, Zod, yup or Angular? A coding agent can move them to validonce and check that nothing changed on generated inputs. The kit is an MCP server (validonce-mcp, for any MCP client) and a Claude Code plugin that bundles it with the validonce-migrate skill.
/plugin marketplace add metatoy/validonce # Claude Code/plugin install validonce@validonceclaude mcp add --transport stdio validonce -- npx -y validonce-mcp # the server aloneThe agent finds each check, rewrites it as a validonce rule, and runs a differential test: the old validator and validonce must accept and reject exactly the same inputs across thousands of generated edge cases. Every run is graded by code, not by a model. In 49 graded runs, including three public apps, every run that passed agreed with the original validator on all generated inputs. Those use well-formed values; formats your code doesn't check at runtime are outside the proof.
Tools, results and the support policy: docs/agentic-migration.md.
What’s in v0.5
- Five rule kinds:
required_when,compare,at_least_one_of,exactly_one_ofandall_or_none. - Six backends: ASP.NET Core with FluentValidation, FastAPI with Pydantic, Fastify, NestJS, Go with Huma, and Spring Boot (Java and Kotlin). They all return the same 422.
- Kubernetes: the CEL rules of custom resources (
x-kubernetes-validations) translate to validonce rules, checked against the API server’s own validation. - Four frontends: React (react-hook-form), Angular (Signal and Reactive Forms), Vue (VeeValidate), and plain HTML or web components.
- Generator plugins: the Zod schemas that kubb, Hey API and orval generate carry the cross-field rules.
- AI tooling: an MCP server and a Claude Code plugin that migrate existing validation and prove it.
- One conformance suite of 125 cases that the C#, Python, TypeScript, Go and Java evaluators all pass.
- A published standard: the rule format has a permanent home at schemas.metatoy.com and is listed on SchemaStore.
- A regex portability linter for
patternrules, which flags patterns that behave differently across JavaScript, Python, Rust and .NET.
A rule, written once
public sealed class SignupValidator : ValidonceValidator<Signup>{ public SignupValidator() { RequiredWhen(x => x.Company, If.Eq(x => x.Plan, "pro")) .WithMessageKey("rules.company_required"); Compare(x => x.End, CompareOp.Ge, x => x.Start) .WithMessageKey("rules.end_after_start"); }}The same two rules reach the browser through the OpenAPI document:
import { rulesFromOpenApi } from "validonce/openapi";import { withRules } from "validonce/zod";const rules = rulesFromOpenApi(openApiDoc, "Signup");const schema = withRules(signupZodSchema, rules);Quick starts for every backend and frontend are in the README, or try them in the playground.
Install
dotnet add package Validonce.AspNetCore # ASP.NET Corepip install validonce # FastAPI / Pydantic (Python 3.10+)go get github.com/metatoy/validonce/go # Go / Humanpm install validonce zod # browser, Fastify, NestJSSpring Boot (Gradle): implementation("com.metatoy:validonce-spring:0.5.0")
| Registry | Package | What it does |
|---|---|---|
| NuGet | Validonce.AspNetCore | ASP.NET Core minimal APIs and MVC: 422 on a broken rule, OpenAPI export |
| NuGet | Validonce.FluentValidation | Write the rules in FluentValidation validators |
| NuGet | Validonce | The core rule model and evaluator for .NET |
| NuGet | Validonce.Cli | dotnet tool, including the regex portability linter |
| PyPI | validonce | Pydantic models and FastAPI |
| npm | validonce | Browser runtime (Zod 4, React, Angular, Vue, plain HTML), Fastify and NestJS servers, Kubernetes CEL translation, kubb / Hey API / orval plugins |
| Go | github.com/metatoy/validonce/go | Go evaluator and builders, Huma and go-playground/validator integration |
| Maven | com.metatoy:validonce-spring | Spring Boot: Bean Validation constraint, springdoc OpenAPI, 422 ProblemDetail (Java and Kotlin) |
| npm | validonce-mcp | MCP server for coding agents: read, check, evaluate and generate rules, and prove a migration |
License
Apache-2.0, copyright 2026 Metatoy LLC. Contributions and issues are welcome on GitHub.