Skip to content

Built-in Rules Reference

Here is a complete list of all types and validators available out of the box.

Built-in Types (Casting Rules)

A field's type defines how the input value will be converted before any other validation rules are run.

Type NameDescription
stringConverts the input to a string. By default, it trims whitespace. Fails if the input is an object or array.
numberConverts the input to a finite number. Empty strings, whitespace-only strings, and non-finite values fail validation.
integerConverts the input to a finite integer. Non-integer numeric values fail validation.
booleanConverts the input to a boolean using explicit true/false tokens such as true, false, 1, 0, yes, no, on, and off. Unknown values fail validation.
arrayEnsures the value is an array. If the input is not already an array, it will be wrapped in one (e.g., 'tag1' becomes ['tag1']). If items is present, every item is validated recursively.
idParses the value into a positive safe integer identifier. It rejects non-canonical forms such as leading zeroes or strings with junk suffixes.
dateConverts a valid date string or timestamp into a Date object normalized to midnight UTC for that calendar day.
dateTimeConverts a valid date string or timestamp into a Date object. MySQL-style YYYY-MM-DD HH:MM:SS strings are interpreted as UTC.
timestampConverts the input to a number, suitable for storing Unix timestamps.
timeConverts the input to a normalized HH:MM:SS string.
serializeConverts any JavaScript value (including objects with circular references) into a single JSON-like string using flatted.
objectRequires a plain object value. With schema, it becomes a nested object contract. With values, it becomes a typed object map. With additionalProperties: true, it becomes either an opaque pass-through object bag or a passthrough nested object when combined with schema. Without any of those options, it is simply a validated plain object value with no child-field rules.
blobPasses the value through unchanged. Intended for binary data like files that don't need casting.
fileConverts primitive file-handle-like values to strings and rejects objects or arrays.
noneThe "identity" type. Passes the value through completely unchanged without any casting.

Built-in Validators (Validation Parameters)

Validators are rules that run after a value has been cast to its proper type.

ParameterDescription
required: trueThe field must be present in the input object. Fails if the key is undefined.
minLength: <number>For string types, validates the minimum character length.
maxLength: <number>For string types, validates the maximum character length.
min: <number>For number types, validates the minimum value.
max: <number>For number types, validates the maximum value.
enum: <array>Restricts the field to one of the declared values. Exported as a standard JSON Schema enum.
notEmpty: trueThe field cannot be an empty string (''). This is different from required, as an empty string is still a defined value.
length: <number>For string types, it truncates the string to the specified length. For number types, it throws an error if the number of digits in the original input exceeds the specified length.
nullable: trueAllows the value for this field to be null. By default, null is not allowed.
nullOnEmpty: trueIf the input value is an empty string (''), it will be cast to null before other validators run.
lowercase: trueTransforms the string to all lowercase.
uppercase: trueTransforms the string to all uppercase.
strictBoolean: trueRestricts a boolean field so the original input must already be a real boolean.
validator: <function>Allows you to provide your own synchronous custom validation function for complex, one-off logic.
defaultTo: <value>If the field is not present in the input object, this value will be used in validation modes that apply defaults. Can be a value or a function that returns a value.
unsigned: truePassive schema metadata indicating non-negative numeric storage intent. Preserved in transport export metadata.
precision: <number>Passive schema metadata for decimal total digits. Preserved in transport export metadata.
scale: <number>Passive schema metadata for decimal fractional digits. Preserved in transport export metadata.
temporalPrecision: <number>Passive schema metadata for time or datetime fractional-second precision. Preserved in transport export metadata.

GPL-3.0-only