kestra-io/kestra · error · PebbleException

The 'nanoId()' function field 'alphabet' must not contain mo

Error message

The 'nanoId()' function field 'alphabet' must not contain more than: %s characters

What it means

The nanoId() function enforces a maximum alphabet length of MAX_ALPHABET_LENGTH (256 characters). If the provided alphabet string exceeds 256 characters, this error fires. The cap exists to keep the byte-rejection loop bounded and memory predictable.

Source

Thrown at core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java:45

        Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
        int length = DEFAULT_LENGTH;
        if (args.containsKey(LENGTH) && (args.get(LENGTH) instanceof Long)) {
            length = parseLength(args, self, lineNumber);
        }
        char[] alphabet = DEFAULT_ALPHABET;
        if (args.containsKey(ALPHABET) && (args.get(ALPHABET) instanceof String)) {
            alphabet = ((String) args.get(ALPHABET)).toCharArray();
        }
        if (alphabet.length == 0) {
            throw new PebbleException(
                null,
                "The 'nanoId()' function field 'alphabet' must not be empty",
                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()
            );

View on GitHub (pinned to 823fada927)

Solutions

  1. Reduce the alphabet to 256 characters or fewer. For most use cases, 16–64 characters is sufficient.
  2. If you need a broader character set, consider generating IDs differently or using the default 64-character URL-safe alphabet.

Example fix

# before
value: "{{ nanoId(alphabet=veryLongAlphabetVar) }}"
# after
value: "{{ nanoId(alphabet='0123456789abcdef') }}"
Defensive patterns

Strategy: validation

Validate before calling

# Ensure alphabet length is within the 256-char limit:
{% if myAlphabet|length <= 256 %}
  {{ nanoId(alphabet=myAlphabet) }}
{% else %}
  {{ nanoId() }}
{% endif %}

Prevention

When it happens

Trigger: Passing an alphabet string longer than 256 characters: {{ nanoId(alphabet='....256+ chars....') }}. A dynamically generated alphabet (e.g. from a large character set variable) that exceeds the cap.

Common situations: The author builds an alphabet from a full Unicode block or concatenates multiple character sets, accidentally exceeding 256 characters.

Related errors


AI-assisted analysis of kestra-io/kestra@823fada927 (2026-08-14). Data as JSON: /api/errors/03090db20df8761d. Report an issue: GitHub.