kestra-io/kestra · error · PebbleException

The 'nanoId()' function field 'length' must be lower than: %

Error message

The 'nanoId()' function field 'length' must be lower than: %s

What it means

The nanoId() function enforces a maximum length of MAX_LENGTH (1000 characters). If the length argument exceeds 1000, this error fires to prevent excessive memory allocation and unreasonably long IDs.

Source

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

                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);
    }

    @Override
    public List<String> getArgumentNames() {
        return List.of(LENGTH, ALPHABET);
    }

    @Override
    public Map<String, String> getArgumentDefaults() {
        HashMap<String, String> defaults = new HashMap<>();
        defaults.put(LENGTH, null);

View on GitHub (pinned to 823fada927)

Solutions

  1. Reduce the length to 1000 or fewer. For ID generation, 8–32 characters is typical.
  2. If you need longer output, concatenate multiple nanoId calls or use a different generation strategy.

Example fix

# before
value: "{{ nanoId(length=5000) }}"
# after
value: "{{ nanoId(length=32) }}"
Defensive patterns

Strategy: validation

Validate before calling

# Ensure length does not exceed 1000:
{% if myLength <= 1000 %}
  {{ nanoId(length=myLength) }}
{% else %}
  {{ nanoId(length=1000) }}
{% endif %}

Prevention

When it happens

Trigger: Calling {{ nanoId(length=5000) }} or passing a dynamic variable for length that exceeds 1000.

Common situations: The author misconfigures a length from an input variable without validation. The author generates very long tokens for a use case that would be better served by a different approach.

Related errors


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