Skip to main content
Length validators check the size of strings, lists, and other collections.
Length validators support transforms when validating strings. Transforms are applied before measuring length.

length!

Checks that the value has exactly the specified length.

min_length!

Checks that the value has at least the specified length.

max_length!

Checks that the value has at most the specified length.

Combining Length Validators

Length Range

With Other Validators

Common Patterns

Response Quality Checks

Array Size Validation

Code Generation

Using Transforms

Transforms are applied before measuring length:

Notes on Length Calculation

  • Strings: Length is the number of characters
  • Arrays: Length is the number of items
  • Objects: Length is the number of keys