Skip to main content
Every callback and net event declares a schema. A schema describes each argument, with limits. Validated input always has a known maximum size.

Rules

Strings

String({ max }). max is required and counts UTF-8 characters. Invalid UTF-8 and control characters are rejected. multiline = true allows tab and line breaks only.

Numbers

Number() and Integer() reject NaN and infinity. Integer turns 5.0 into 5. min and max are optional.

Booleans and enums

Boolean(). Enum({ 'cash', 'bank' }) accepts listed strings, numbers or booleans only.

Vectors

Vector2/3/4({ maxComponent? }) check the native type and finite components. Never trust them as positions.

Arrays and maps

Array(item, { max }) and Map(key, value, { max }). max is required. Oversized tables are rejected before scanning the rest.

Objects

Object({ field = rule }) rejects unknown keys by default. { strict = false } drops them instead. Wrap optional fields in Optional.
A missing max on String, Array or Map is an error in your editor and raises when the rule is built. Unbounded input cannot be accepted by accident.

Validate yourself

Callbacks and net events validate for you. For other input, use Validate or Check:
args.n is the number of declared arguments, so table.unpack(args, 1, args.n) keeps trailing optional arguments.

Failure details

Details name the exact path that failed, for your server logs:
Details never echo large input back. Clients only ever get invalid_args.

Custom checks

Every rule accepts a validate function that runs after the built-in checks, on the normalized value:
Return true, or false with a message. A crashing validate fails with failed custom validation, without a stack.

Behavior to know

  • Validate tolerates trailing nil values and rejects extra ones. More than 8 extra arguments are rejected before unpacking.
  • Optional arguments MUST be trailing in Define.
  • Validated tables are fresh copies. Metatables and unknown keys never pass through.
  • Array items and map keys or values cannot be Optional.
See every builder and option in the Schema reference.