Open source · Metatoy

validonce

Write cross-field validation rules once, on the server, and enforce the same rules in the browser.

v0.5.0Apache-2.0© 2026 Metatoy LLCC# · Python · TypeScript · Go · Java/Kotlin

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

01 · Server rules
FluentValidation (C#)
RequiredWhen · Compare
Pydantic (Python)
__rules__ = [ when(…).require(…) ]
Fastify / NestJS (TypeScript)
validonce/rules
Huma (Go)
struct rules
Spring Boot (Java / Kotlin)
Bean Validation
Kubernetes CRDs (CEL)
x-kubernetes-validations
02 · OpenAPI document
The rules travel as data
components.schemas.Signup
"x-validonce": [ … ]
Five rule kinds, one format
03 · Browser
validonce runtime
withRules(zod)
React (react-hook-form)
Angular (Signal / Reactive Forms)
Vue (VeeValidate)
Web components (validonce/dom)
The server always enforces
every request; a broken rule returns 422
422 · same issue shape, mapped back onto each field

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.

Terminal
/plugin marketplace add metatoy/validonce   # Claude Code/plugin install validonce@validonceclaude mcp add --transport stdio validonce -- npx -y validonce-mcp   # the server alone

The 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_of and all_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 pattern rules, which flags patterns that behave differently across JavaScript, Python, Rust and .NET.

A rule, written once

C#SignupValidator.cs
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:

TypeScriptsignup-form.ts
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

Terminal
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, NestJS

Spring Boot (Gradle): implementation("com.metatoy:validonce-spring:0.5.0")

RegistryPackageWhat it does
NuGetValidonce.AspNetCoreASP.NET Core minimal APIs and MVC: 422 on a broken rule, OpenAPI export
NuGetValidonce.FluentValidationWrite the rules in FluentValidation validators
NuGetValidonceThe core rule model and evaluator for .NET
NuGetValidonce.Clidotnet tool, including the regex portability linter
PyPIvalidoncePydantic models and FastAPI
npmvalidonceBrowser runtime (Zod 4, React, Angular, Vue, plain HTML), Fastify and NestJS servers, Kubernetes CEL translation, kubb / Hey API / orval plugins
Gogithub.com/metatoy/validonce/goGo evaluator and builders, Huma and go-playground/validator integration
Mavencom.metatoy:validonce-springSpring Boot: Bean Validation constraint, springdoc OpenAPI, 422 ProblemDetail (Java and Kotlin)
npmvalidonce-mcpMCP 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.