Documentation Index
Fetch the complete documentation index at: https://docs.timbal.ai/llms.txt
Use this file to discover all available pages before exploring further.
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.
generate_code:
output:
length!: 6
| Parameter | Type | Description |
|---|
| value | integer | Exact required length |
# Exact code length
generate_pin:
output:
length!: 4
# Fixed-length ID
create_id:
output:
length!: 36 # UUID length
# Specific list size
get_top_results:
output:
length!: 5
min_length!
Checks that the value has at least the specified length.
| Parameter | Type | Description |
|---|
| value | integer | Minimum required length |
# Ensure substantive response
output:
min_length!: 50
# Require at least one result
search_products:
output:
min_length!: 1
# Validate input length
validate_password:
input:
password:
min_length!: 8
max_length!
Checks that the value has at most the specified length.
output:
max_length!: 1000
| Parameter | Type | Description |
|---|
| value | integer | Maximum allowed length |
# Limit response length
output:
max_length!: 500
# Limit results returned
search_products:
output:
max_length!: 10
# Username length limit
validate_username:
input:
username:
max_length!: 32
Combining Length Validators
Length Range
output:
min_length!: 50
max_length!: 500
With Other Validators
output:
not_null!: true
type!: "string"
min_length!: 10
max_length!: 1000
contains!: "result"
Common Patterns
Response Quality Checks
output:
not_null!: true
type!: "string"
min_length!: 20 # Not too short
max_length!: 2000 # Not too long
Array Size Validation
search_products:
output:
type!: "array"
min_length!: 1
max_length!: 50
recommend:
output:
length!: 3 # Exactly 3 recommendations
Code Generation
generate_pin:
output:
type!: "string"
length!: 4
pattern!: "\\d{4}"
generate_code:
output:
type!: "string"
length!: 6
pattern!: "[A-Z0-9]{6}"
Transforms are applied before measuring length:
# Trim whitespace before checking length
output:
min_length!:
value: 10
transform: trim
# Collapse whitespace then check length
output:
max_length!:
value: 100
transform: [trim, collapse_whitespace]
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
# String length (characters)
output: # "Hello" has length 5
length!: 5
# Array length (items)
items: # [1, 2, 3] has length 3
length!: 3
# Object length (keys)
config: # {"a": 1, "b": 2} has length 2
length!: 2