{"record":{"id":"19db4624ea5980e7","repo":"kestra-io/kestra","slug":"the-nanoid-function-field-length-must-be-low","errorCode":null,"errorMessage":"The 'nanoId()' function field 'length' must be lower than: %s","messagePattern":"The 'nanoId\\(\\)' function field 'length' must be lower than: (.+?)","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java","lineNumber":66,"sourceCode":"                lineNumber,\n                self.getName()\n            );\n        }\n        return createNanoID(length, alphabet);\n    }\n\n    private static int parseLength(Map<String, Object> args, PebbleTemplate self, int lineNumber) {\n        var value = (Long) args.get(LENGTH);\n        if (value < 1) {\n            throw new PebbleException(\n                null,\n                \"The 'nanoId()' function field 'length' must be greater than: 0\",\n                lineNumber,\n                self.getName()\n            );\n        }\n        if (value > MAX_LENGTH) {\n            throw new PebbleException(\n                null,\n                \"The 'nanoId()' function field 'length' must be lower than: \" + MAX_LENGTH,\n                lineNumber,\n                self.getName()\n            );\n        }\n        return Math.toIntExact(value);\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(LENGTH, ALPHABET);\n    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        HashMap<String, String> defaults = new HashMap<>();\n        defaults.put(LENGTH, null);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/NanoIDFunction.java#L48-L84","documentation":"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.","triggerScenarios":"Calling {{ nanoId(length=5000) }} or passing a dynamic variable for length that exceeds 1000.","commonSituations":"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.","solutions":["Reduce the length to 1000 or fewer. For ID generation, 8–32 characters is typical.","If you need longer output, concatenate multiple nanoId calls or use a different generation strategy."],"exampleFix":"# before\nvalue: \"{{ nanoId(length=5000) }}\"\n# after\nvalue: \"{{ nanoId(length=32) }}\"","handlingStrategy":"validation","validationCode":"# Ensure length does not exceed 1000:\n{% if myLength <= 1000 %}\n  {{ nanoId(length=myLength) }}\n{% else %}\n  {{ nanoId(length=1000) }}\n{% endif %}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 8–32 character lengths for typical ID generation.","Validate dynamic length variables against the upper bound.","If longer output is needed, concatenate multiple nanoId calls."],"tags":["pebble-function","nanoid","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}