Rule
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
id | 1 | string | optional |
|
message | 2 | string | optional |
|
expression | 3 | string | optional |
|
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
id | 1 | string | optional |
|
message | 2 | string | optional |
|
expression | 3 | string | optional |
|
MessageRules represents validation rules that are applied to the entire message. It includes disabling options and a list of Rule messages representing Common Expression Language (CEL) validation rules.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
cel_expression | 5 | string | repeated |
This is a simplified form of the For more information, see our documentation. |
cel | 3 | Rule | repeated |
|
oneof | 4 | MessageOneofRule | repeated |
This will enforce oneof-like constraints with a few features not provided by actual Protobuf oneof declarations:
Note that adding a field to a |
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
fields | 1 | string | repeated | A list of field names to include in the oneof. All field names must be defined in the message. At least one field must be specified, and duplicates are not permitted. |
required | 2 | bool | optional | If true, one of the fields specified must be set. |
The OneofRules message type enables you to manage rules for
oneof fields in your protobuf messages.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
required | 1 | bool | optional | If |
FieldRules encapsulates the rules for each type of field. Depending on the field, the correct set should be used to ensure proper validations.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
cel_expression | 29 | string | repeated |
This is a simplified form of the For more information, see our documentation. |
cel | 23 | Rule | repeated |
|
required | 25 | bool | optional | If
All fields in the example above track presence. By default, Protovalidate
ignores rules on those fields if no value is set. Fields that don't track presence are always validated by Protovalidate,
whether they are set or not. It is not necessary to add
To learn which fields track presence, see the Field Presence cheat sheet. Note: While field rules can be applied to repeated items, map keys, and map
values, the elements are always considered to be set. Consequently,
specifying |
ignore | 27 | Ignore | optional | Ignore validation rules on the field if its value matches the specified
criteria. See the |
float | 1 | FloatRules | optional | Scalar Field Types |
double | 2 | DoubleRules | optional | |
int32 | 3 | Int32Rules | optional | |
int64 | 4 | Int64Rules | optional | |
uint32 | 5 | UInt32Rules | optional | |
uint64 | 6 | UInt64Rules | optional | |
sint32 | 7 | SInt32Rules | optional | |
sint64 | 8 | SInt64Rules | optional | |
fixed32 | 9 | Fixed32Rules | optional | |
fixed64 | 10 | Fixed64Rules | optional | |
sfixed32 | 11 | SFixed32Rules | optional | |
sfixed64 | 12 | SFixed64Rules | optional | |
bool | 13 | BoolRules | optional | |
string | 14 | StringRules | optional | |
bytes | 15 | BytesRules | optional | |
enum | 16 | EnumRules | optional | Complex Field Types |
repeated | 18 | RepeatedRules | optional | |
map | 19 | MapRules | optional | |
any | 20 | AnyRules | optional | Well-Known Field Types |
duration | 21 | DurationRules | optional | |
field_mask | 28 | FieldMaskRules | optional | |
timestamp | 22 | TimestampRules | optional |
PredefinedRules are custom rules that can be re-used with multiple fields.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
cel | 1 | Rule | repeated |
|
FloatRules describes the rules applied to float values. These
rules may also be applied to the google.protobuf.FloatValue Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | float | optional |
|
lt | 2 | float | optional |
|
lte | 3 | float | optional |
|
gt | 4 | float | optional |
|
gte | 5 | float | optional |
|
in | 6 | float | repeated |
|
not_in | 7 | float | repeated |
|
finite | 8 | bool | optional |
|
example | 9 | float | repeated |
|
DoubleRules describes the rules applied to double values. These
rules may also be applied to the google.protobuf.DoubleValue Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | double | optional |
|
lt | 2 | double | optional |
|
lte | 3 | double | optional |
|
gt | 4 | double | optional |
|
gte | 5 | double | optional |
|
in | 6 | double | repeated |
|
not_in | 7 | double | repeated |
|
finite | 8 | bool | optional |
|
example | 9 | double | repeated |
|
Int32Rules describes the rules applied to int32 values. These
rules may also be applied to the google.protobuf.Int32Value Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | int32 | optional |
|
lt | 2 | int32 | optional |
|
lte | 3 | int32 | optional |
|
gt | 4 | int32 | optional |
|
gte | 5 | int32 | optional |
|
in | 6 | int32 | repeated |
|
not_in | 7 | int32 | repeated |
|
example | 8 | int32 | repeated |
|
Int64Rules describes the rules applied to int64 values. These
rules may also be applied to the google.protobuf.Int64Value Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | int64 | optional |
|
lt | 2 | int64 | optional |
|
lte | 3 | int64 | optional |
|
gt | 4 | int64 | optional |
|
gte | 5 | int64 | optional |
|
in | 6 | int64 | repeated |
|
not_in | 7 | int64 | repeated |
|
example | 9 | int64 | repeated |
|
UInt32Rules describes the rules applied to uint32 values. These
rules may also be applied to the google.protobuf.UInt32Value Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | uint32 | optional |
|
lt | 2 | uint32 | optional |
|
lte | 3 | uint32 | optional |
|
gt | 4 | uint32 | optional |
|
gte | 5 | uint32 | optional |
|
in | 6 | uint32 | repeated |
|
not_in | 7 | uint32 | repeated |
|
example | 8 | uint32 | repeated |
|
UInt64Rules describes the rules applied to uint64 values. These
rules may also be applied to the google.protobuf.UInt64Value Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | uint64 | optional |
|
lt | 2 | uint64 | optional |
|
lte | 3 | uint64 | optional |
|
gt | 4 | uint64 | optional |
|
gte | 5 | uint64 | optional |
|
in | 6 | uint64 | repeated |
|
not_in | 7 | uint64 | repeated |
|
example | 8 | uint64 | repeated |
|
SInt32Rules describes the rules applied to sint32 values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | sint32 | optional |
|
lt | 2 | sint32 | optional |
|
lte | 3 | sint32 | optional |
|
gt | 4 | sint32 | optional |
|
gte | 5 | sint32 | optional |
|
in | 6 | sint32 | repeated |
|
not_in | 7 | sint32 | repeated |
|
example | 8 | sint32 | repeated |
|
SInt64Rules describes the rules applied to sint64 values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | sint64 | optional |
|
lt | 2 | sint64 | optional |
|
lte | 3 | sint64 | optional |
|
gt | 4 | sint64 | optional |
|
gte | 5 | sint64 | optional |
|
in | 6 | sint64 | repeated |
|
not_in | 7 | sint64 | repeated |
|
example | 8 | sint64 | repeated |
|
Fixed32Rules describes the rules applied to fixed32 values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | fixed32 | optional |
|
lt | 2 | fixed32 | optional |
|
lte | 3 | fixed32 | optional |
|
gt | 4 | fixed32 | optional |
|
gte | 5 | fixed32 | optional |
|
in | 6 | fixed32 | repeated |
|
not_in | 7 | fixed32 | repeated |
|
example | 8 | fixed32 | repeated |
|
Fixed64Rules describes the rules applied to fixed64 values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | fixed64 | optional |
|
lt | 2 | fixed64 | optional |
|
lte | 3 | fixed64 | optional |
|
gt | 4 | fixed64 | optional |
|
gte | 5 | fixed64 | optional |
|
in | 6 | fixed64 | repeated |
|
not_in | 7 | fixed64 | repeated |
|
example | 8 | fixed64 | repeated |
|
SFixed32Rules describes the rules applied to fixed32 values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | sfixed32 | optional |
|
lt | 2 | sfixed32 | optional |
|
lte | 3 | sfixed32 | optional |
|
gt | 4 | sfixed32 | optional |
|
gte | 5 | sfixed32 | optional |
|
in | 6 | sfixed32 | repeated |
|
not_in | 7 | sfixed32 | repeated |
|
example | 8 | sfixed32 | repeated |
|
SFixed64Rules describes the rules applied to fixed64 values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | sfixed64 | optional |
|
lt | 2 | sfixed64 | optional |
|
lte | 3 | sfixed64 | optional |
|
gt | 4 | sfixed64 | optional |
|
gte | 5 | sfixed64 | optional |
|
in | 6 | sfixed64 | repeated |
|
not_in | 7 | sfixed64 | repeated |
|
example | 8 | sfixed64 | repeated |
|
BoolRules describes the rules applied to bool values. These rules
may also be applied to the google.protobuf.BoolValue Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | bool | optional |
|
example | 2 | bool | repeated |
|
StringRules describes the rules applied to string values These
rules may also be applied to the google.protobuf.StringValue Well-Known-Type.
| Name | Tag | Type | Label | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
const | 1 | string | optional |
| ||||||||||||
len | 19 | uint64 | optional |
| ||||||||||||
min_len | 2 | uint64 | optional |
| ||||||||||||
max_len | 3 | uint64 | optional |
| ||||||||||||
len_bytes | 20 | uint64 | optional |
| ||||||||||||
min_bytes | 4 | uint64 | optional |
| ||||||||||||
max_bytes | 5 | uint64 | optional |
| ||||||||||||
pattern | 6 | string | optional |
| ||||||||||||
prefix | 7 | string | optional |
| ||||||||||||
suffix | 8 | string | optional |
| ||||||||||||
contains | 9 | string | optional |
| ||||||||||||
not_contains | 23 | string | optional |
| ||||||||||||
in | 10 | string | repeated |
| ||||||||||||
not_in | 11 | string | repeated |
| ||||||||||||
email | 12 | bool | optional |
Conforms to the definition for a valid email address from the HTML standard. Note that this standard willfully deviates from RFC 5322, which allows many unexpected forms of email addresses and will easily match a typographical error. If the field value isn't a valid email address, an error message will be generated.
| ||||||||||||
hostname | 13 | bool | optional |
A valid hostname follows the rules below:
If the field value isn't a valid hostname, an error message will be generated.
| ||||||||||||
ip | 14 | bool | optional |
IPv4 addresses are expected in the dotted decimal format—for example, "192.168.5.21". IPv6 addresses are expected in their text representation—for example, "::1", or "2001:0DB8:ABCD:0012::0". Both formats are well-defined in the internet standard RFC 3986. Zone identifiers for IPv6 addresses (for example, "fe80::a%en1") are supported. If the field value isn't a valid IP address, an error message will be generated.
| ||||||||||||
ipv4 | 15 | bool | optional |
| ||||||||||||
ipv6 | 16 | bool | optional |
| ||||||||||||
uri | 17 | bool | optional |
URI is defined in the internet standard RFC 3986. Zone Identifiers in IPv6 address literals are supported (RFC 6874). If the field value isn't a valid URI, an error message will be generated.
| ||||||||||||
uri_ref | 18 | bool | optional |
URI, URI Reference, and Relative Reference are defined in the internet standard RFC 3986. Zone Identifiers in IPv6 address literals are supported (RFC 6874). If the field value isn't a valid URI Reference, an error message will be generated.
| ||||||||||||
address | 21 | bool | optional |
| ||||||||||||
uuid | 22 | bool | optional |
| ||||||||||||
tuuid | 33 | bool | optional |
| ||||||||||||
ip_with_prefixlen | 26 | bool | optional |
| ||||||||||||
ipv4_with_prefixlen | 27 | bool | optional |
| ||||||||||||
ipv6_with_prefixlen | 28 | bool | optional |
| ||||||||||||
ip_prefix | 29 | bool | optional |
The prefix must have all zeros for the unmasked bits. For example, "2001:0DB8:ABCD:0012::0/64" designates the left-most 64 bits for the prefix, and the remaining 64 bits must be zero. If the field value isn't a valid IP prefix, an error message will be generated.
| ||||||||||||
ipv4_prefix | 30 | bool | optional |
The prefix must have all zeros for the unmasked bits. For example, "192.168.0.0/16" designates the left-most 16 bits for the prefix, and the remaining 16 bits must be zero. If the field value isn't a valid IPv4 prefix, an error message will be generated.
| ||||||||||||
ipv6_prefix | 31 | bool | optional |
The prefix must have all zeros for the unmasked bits. For example, "2001:0DB8:ABCD:0012::0/64" designates the left-most 64 bits for the prefix, and the remaining 64 bits must be zero. If the field value is not a valid IPv6 prefix, an error message will be generated.
| ||||||||||||
host_and_port | 32 | bool | optional |
The host can be one of:
The port is separated by a colon. It must be non-empty, with a decimal number in the range of 0-65535, inclusive.
| ||||||||||||
ulid | 35 | bool | optional |
| ||||||||||||
protobuf_fqn | 37 | bool | optional |
A fully-qualified Protobuf name is a dot-separated list of Protobuf identifiers, where each identifier starts with a letter or underscore and is followed by zero or more letters, underscores, or digits. Examples: "buf.validate", "google.protobuf.Timestamp", "my_package.MyMessage". Note: historically, fully-qualified Protobuf names were represented with a leading
dot (for example, ".buf.validate.StringRules"). Modern Protobuf does not use the
leading dot, and most fully-qualified names are represented without it. Use
If the field value isn't a valid fully-qualified Protobuf name, an error message will be generated.
| ||||||||||||
protobuf_dot_fqn | 38 | bool | optional |
A fully-qualified Protobuf name with a leading dot is a dot followed by a dot-separated list of Protobuf identifiers, where each identifier starts with a letter or underscore and is followed by zero or more letters, underscores, or digits. Examples: ".buf.validate", ".google.protobuf.Timestamp", ".my_package.MyMessage". Note: this is the historical representation of fully-qualified Protobuf names,
where a leading dot denotes an absolute reference. Modern Protobuf does not use
the leading dot, and most fully-qualified names are represented without it. Most
users will want to use If the field value isn't a valid fully-qualified Protobuf name with a leading dot, an error message will be generated.
| ||||||||||||
well_known_regex | 24 | KnownRegex | optional |
KnownRegex
| ||||||||||||
strict | 25 | bool | optional | This applies to regexes | ||||||||||||
example | 34 | string | repeated |
|
BytesRules describe the rules applied to bytes values. These rules
may also be applied to the google.protobuf.BytesValue Well-Known-Type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | bytes | optional |
|
len | 13 | uint64 | optional |
|
min_len | 2 | uint64 | optional |
|
max_len | 3 | uint64 | optional |
|
pattern | 4 | string | optional |
|
prefix | 5 | bytes | optional |
|
suffix | 6 | bytes | optional |
|
contains | 7 | bytes | optional |
|
in | 8 | bytes | repeated |
|
not_in | 9 | bytes | repeated |
|
ip | 10 | bool | optional |
|
ipv4 | 11 | bool | optional |
|
ipv6 | 12 | bool | optional |
|
uuid | 15 | bool | optional |
|
example | 14 | bytes | repeated |
|
EnumRules describe the rules applied to enum values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | int32 | optional |
|
defined_only | 2 | bool | optional |
|
in | 3 | int32 | repeated |
|
not_in | 4 | int32 | repeated |
|
example | 5 | int32 | repeated |
|
RepeatedRules describe the rules applied to repeated values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
min_items | 1 | uint64 | optional |
Note that
|
max_items | 2 | uint64 | optional |
|
unique | 3 | bool | optional |
|
items | 4 | FieldRules | optional |
Note that the |
MapRules describe the rules applied to map values.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
min_pairs | 1 | uint64 | optional | Specifies the minimum number of key-value pairs allowed. If the field has fewer key-value pairs than specified, an error message is generated.
|
max_pairs | 2 | uint64 | optional | Specifies the maximum number of key-value pairs allowed. If the field has more key-value pairs than specified, an error message is generated.
|
keys | 4 | FieldRules | optional | Specifies the rules to be applied to each key in the field.
Note that the |
values | 5 | FieldRules | optional | Specifies the rules to be applied to the value of each key in the
field. Message values will still have their validations evaluated unless
Note that the |
AnyRules describe rules applied exclusively to the google.protobuf.Any well-known type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
in | 2 | string | repeated |
|
not_in | 3 | string | repeated |
|
DurationRules describe the rules applied exclusively to the google.protobuf.Duration well-known type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 2 | google.protobuf.Duration | optional |
|
lt | 3 | google.protobuf.Duration | optional |
|
lte | 4 | google.protobuf.Duration | optional |
|
gt | 5 | google.protobuf.Duration | optional |
|
gte | 6 | google.protobuf.Duration | optional |
|
in | 7 | google.protobuf.Duration | repeated |
|
not_in | 8 | google.protobuf.Duration | repeated |
|
example | 9 | google.protobuf.Duration | repeated |
|
FieldMaskRules describe rules applied exclusively to the google.protobuf.FieldMask well-known type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 1 | google.protobuf.FieldMask | optional |
|
in | 2 | string | repeated |
|
not_in | 3 | string | repeated |
|
example | 4 | google.protobuf.FieldMask | repeated |
|
TimestampRules describe the rules applied exclusively to the google.protobuf.Timestamp well-known type.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
const | 2 | google.protobuf.Timestamp | optional |
|
lt | 3 | google.protobuf.Timestamp | optional |
|
lte | 4 | google.protobuf.Timestamp | optional |
|
lt_now | 7 | bool | optional |
|
gt | 5 | google.protobuf.Timestamp | optional |
|
gte | 6 | google.protobuf.Timestamp | optional |
|
gt_now | 8 | bool | optional |
|
within | 9 | google.protobuf.Duration | optional |
|
example | 10 | google.protobuf.Timestamp | repeated |
|
Violations is a collection of Violation messages. This message type is returned by
Protovalidate when a proto message fails to meet the requirements set by the Rule validation rules.
Each individual violation is represented by a Violation message.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
violations | 1 | Violation | repeated |
|
Violation represents a single instance where a validation rule, expressed
as a Rule, was not met. It provides information about the field that
caused the violation, the specific rule that wasn't fulfilled, and a
human-readable error message.
For example, consider the following message:
message User {
int32 age = 1 [(buf.validate.field).cel = {
id: "user.age",
expression: "this < 18 ? 'User must be at least 18 years old' : ''",
}];
}
It could produce the following violation:
{
"ruleId": "user.age",
"message": "User must be at least 18 years old",
"field": {
"elements": [
{
"fieldNumber": 1,
"fieldName": "age",
"fieldType": "TYPE_INT32"
}
]
},
"rule": {
"elements": [
{
"fieldNumber": 23,
"fieldName": "cel",
"fieldType": "TYPE_MESSAGE",
"index": "0"
}
]
}
}
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
field | 5 | FieldPath | optional |
For example, consider the following message:
It could produce the following violation: |
rule | 6 | FieldPath | optional |
For example, consider the following message:
It could produce the following violations: |
rule_id | 2 | string | optional |
|
message | 3 | string | optional |
|
for_key | 4 | bool | optional |
|
FieldPath provides a path to a nested protobuf field.
This message provides enough information to render a dotted field path even without protobuf descriptors. It also provides enough information to resolve a nested field through unknown wire data.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
elements | 1 | FieldPathElement | repeated |
|
FieldPathElement provides enough information to nest through a single protobuf field.
If the selected field is a map or repeated field, the subscript value selects a specific element from it.
A path that refers to a value nested under a map key or repeated field index will have a subscript value.
The field_type field allows unambiguous resolution of a field even if descriptors are not available.
| Name | Tag | Type | Label | Description |
|---|---|---|---|---|
field_number | 1 | int32 | optional |
|
field_name | 2 | string | optional |
|
field_type | 3 | google.protobuf.FieldDescriptorProto.Type | optional |
This value is provided to make it possible to traverse unknown fields through wire data. When traversing wire data, be mindful of both packed1 and delimited2 encoding schemes. N.B.: Although groups are deprecated, the corresponding delimited encoding scheme is not, and can be explicitly used in Protocol Buffers 2023 Edition. |
key_type | 4 | google.protobuf.FieldDescriptorProto.Type | optional |
|
value_type | 5 | google.protobuf.FieldDescriptorProto.Type | optional |
|
index | 6 | uint64 | optional |
|
bool_key | 7 | bool | optional |
|
int_key | 8 | int64 | optional |
|
uint_key | 9 | uint64 | optional |
|
string_key | 10 | string | optional |
|
Specifies how FieldRules.ignore behaves, depending on the field's value, and
whether the field tracks presence.
| Name | Value | Description |
|---|---|---|
IGNORE_UNSPECIFIED | 0 | Ignore rules if the field tracks presence and is unset. This is the default behavior. In proto3, only message fields, members of a Protobuf
In contrast, the following fields track presence, and are only validated if a value is set:
To ensure that such a field is set, add the To learn which fields track presence, see the Field Presence cheat sheet. |
IGNORE_IF_ZERO_VALUE | 1 | Ignore rules if the field is unset, or set to the zero value. The zero value depends on the field type:
For fields that track presence (e.g. adding the |
IGNORE_ALWAYS | 3 | Always ignore rules, including the This is useful for ignoring the rules of a referenced message, or to temporarily ignore rules during development. |
KnownRegex contains some well-known patterns.
Rules specify the validations to be performed on this message. By default, no validation is performed against a message.
Extends google.protobuf.MessageOptions
Rules specify the validations to be performed on this oneof. By default, no validation is performed against a oneof.
Extends google.protobuf.OneofOptions
Rules specify the validations to be performed on this field. By default, no validation is performed against a field.
Extends google.protobuf.FieldOptions
Specifies predefined rules. When extending a standard rule message, this adds additional CEL expressions that apply when the extension is used.
extend buf.validate.Int32Rules {
bool is_zero = 1001 [(buf.validate.predefined).cel = {
id: "int32.is_zero",
message: "must be zero",
expression: "!rule || this == 0",
}];
}
message Foo {
int32 reserved = 1 [(buf.validate.field).int32.(is_zero) = true];
}
Extends google.protobuf.FieldOptions
Rulerepresents a validation rule written in the Common Expression Language (CEL) syntax. Each Rule includes a unique identifier, an optional error message, and the CEL expression to evaluate. For more information, see our documentation.