Skip to Content

Differences from protovalidate

The cases where a generated schema and protovalidate disagree.

Frontend validation helps the user while they type. Validate on the server with protovalidate as well.

The tests of the plugin run the same values through the generated schemas and through @bufbuild/protovalidate. They record each case below.

String length in Valibot

min_len, max_len, and len count Unicode code points in protovalidate and in Zod. minLength in Valibot counts UTF-16 code units. The counts differ for characters outside the Basic Multilingual Plane, such as emoji.

The Valibot schema is stricter for max_len and looser for min_len.

Regular expressions

protovalidate uses RE2 syntax. The generated code uses the JavaScript RegExp with the u flag.

The plugin compiles each pattern during generation. A pattern that fails is an unsupported rule. The check uses the Node.js version that runs the plugin, so a pattern with newer syntax, such as (?i:...), passes on Node 26 and fails to load in a browser that lacks it.

NaN and infinite numbers

Valibot and Zod reject NaN for every float and double field. Zod also rejects Infinity. protovalidate accepts both values unless a rule excludes them.

float bounds

A float rule value is a 32-bit float, so gte: 0.1 reads back as 0.10000000149011612. The plugin emits the shortest decimal that rounds to the same 32-bit float, here 0.1. The value the user types then passes, as it does on the server after the wire encoding.

Formats

email, uri, and the other formats follow the implementation of the library. Edge cases differ from the protovalidate definitions.

IGNORE_IF_ZERO_VALUE on bytes, repeated, and map

The plugin leaves out the rules of the field and reports the rule as unsupported.

64-bit integers with jstype = JS_STRING

The schema checks that the string is a decimal integer. It does not check the 64-bit range or numeric rules.

Mutually recursive messages

@bufbuild/protovalidate 1.3.0 does not validate a message that it reaches again through another message. The generated schemas validate it.

isolatedDeclarations

This is a limit of the generated code, not a difference in validation. A generated file exports const schemas whose types TypeScript infers, as every Valibot and Zod schema does. TypeScript rejects such an export under isolatedDeclarations.

In a project that uses isolatedDeclarations, put the generated directory in a TypeScript project that does not set the option.