kestra-io/kestra · error · PebbleException
The 'nanoId()' function field 'length' must be greater than:
Error message
The 'nanoId()' function field 'length' must be greater than: 0
What it means
The nanoId() function validates that the length argument, if provided, is at least 1. A length of 0 or a negative number triggers this error. The default length is 21 if no length argument is given. Note that this check only fires when the length argument is present and is a Long (Pebble numeric literals are Long).
Source
Thrown at core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java:58
lineNumber,
self.getName()
);
}
if (alphabet.length > MAX_ALPHABET_LENGTH) {
throw new PebbleException(
null,
"The 'nanoId()' function field 'alphabet' must not contain more than: " + MAX_ALPHABET_LENGTH + " characters",
lineNumber,
self.getName()
);
}
return createNanoID(length, alphabet);
}
private static int parseLength(Map<String, Object> args, PebbleTemplate self, int lineNumber) {
var value = (Long) args.get(LENGTH);
if (value < 1) {
throw new PebbleException(
null,
"The 'nanoId()' function field 'length' must be greater than: 0",
lineNumber,
self.getName()
);
}
if (value > MAX_LENGTH) {
throw new PebbleException(
null,
"The 'nanoId()' function field 'length' must be lower than: " + MAX_LENGTH,
lineNumber,
self.getName()
);
}
return Math.toIntExact(value);
}
@OverrideView on GitHub (pinned to 823fada927)
Solutions
- Provide a length of at least 1: {{ nanoId(length=8) }}.
- Omit the length argument to use the default of 21.
- Guard dynamic length values: {% if myLen > 0 %}{{ nanoId(length=myLen) }}{% else %}{{ nanoId() }}{% endif %}.
Example fix
# before
value: "{{ nanoId(length=0) }}"
# after
value: "{{ nanoId(length=8) }}" Defensive patterns
Strategy: validation
Validate before calling
# Ensure length is at least 1, or omit it for the default of 21:
{% if myLength is not null and myLength > 0 %}
{{ nanoId(length=myLength) }}
{% else %}
{{ nanoId() }}
{% endif %} Prevention
- Omit the length argument to use the default of 21.
- Validate dynamic length variables are positive integers.
- Guard against zero-length edge cases in conditional logic.
When it happens
Trigger: Calling {{ nanoId(length=0) }} or {{ nanoId(length=-5) }}. Passing a dynamic variable for length that resolves to 0 or a negative number.
Common situations: The author sets length from a variable that is conditionally computed and can be 0 in edge cases. The author misunderstands the function and passes 0 expecting a 'default' length.
Related errors
- The 'nanoId()' function field 'alphabet' must not be empty
- The 'nanoId()' function field 'alphabet' must not contain mo
- The 'nanoId()' function field 'length' must be lower than: %
- In 'randomIn()' upper is less than lower
- Migration script [<scriptId>] has no checksum to repair.
AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14).
Data as JSON: /api/errors/5534fa58c6dceaa7.
Report an issue: GitHub.