{"record":{"id":"423994f3b5b8ab7e","repo":"kestra-io/kestra","slug":"in-randomin-upper-is-less-than-lower","errorCode":null,"errorMessage":"In 'randomIn()' upper is less than lower","messagePattern":"In 'randomIn\\(\\)' upper is less than lower","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/RandomIntFunction.java","lineNumber":19,"sourceCode":"package io.kestra.core.runners.pebble.functions;\n\nimport java.util.List;\nimport java.util.Map;\n\nimport io.pebbletemplates.pebble.error.PebbleException;\nimport io.pebbletemplates.pebble.template.EvaluationContext;\nimport io.pebbletemplates.pebble.template.PebbleTemplate;\n\npublic class RandomIntFunction implements KestraFunction {\n    public static final String NAME = \"randomInt\";\n\n    @Override\n    public Object execute(\n        Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        Long lower = getArgument(args, \"lower\", self, lineNumber);\n        Long upper = getArgument(args, \"upper\", self, lineNumber);\n        if (upper < lower) {\n            throw new PebbleException(\n                null,\n                \"In 'randomIn()' upper is less than lower\",\n                lineNumber,\n                self.getName()\n            );\n        }\n        return (int) (Math.floor(Math.random() * (upper - lower)) + lower);\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(\"lower\", \"upper\");\n    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        return Map.of(\"lower\", \"0\", \"upper\", \"10\");\n    }","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/RandomIntFunction.java#L1-L37","documentation":"The randomInt(lower, upper) Pebble function validates that upper >= lower before computing the random value. If upper is strictly less than lower, this error fires. Note: the error message incorrectly says 'randomIn()' — this is a copy-paste bug in the source; the actual function name is randomInt(). The check itself is correct.","triggerScenarios":"Calling {{ randomInt(lower=10, upper=5) }} where upper < lower. Passing dynamic bounds where the upper bound variable resolves to a smaller value than the lower bound.","commonSituations":"The author swaps the lower and upper arguments by mistake. Dynamic bounds from user input or task outputs have an unexpected ordering (e.g. a date range query returns min > max).","solutions":["Ensure upper >= lower: {{ randomInt(lower=5, upper=10) }}.","If bounds are dynamic, swap them when needed: {% set lo = min(a, b) %}{% set hi = max(a, b) %}{{ randomInt(lower=lo, upper=hi) }}.","Be aware the error text references 'randomIn()' — this is a known message bug, not a different function."],"exampleFix":"# before\nvalue: \"{{ randomInt(lower=10, upper=5) }}\"\n# after\nvalue: \"{{ randomInt(lower=5, upper=10) }}\"","handlingStrategy":"validation","validationCode":"# Ensure upper >= lower before calling randomInt:\n{% set lo = min(lowerVal, upperVal) %}\n{% set hi = max(lowerVal, upperVal) %}\n{{ randomInt(lower=lo, upper=hi) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always verify lower <= upper before calling randomInt.","Use min()/max() to normalize dynamic bounds.","Be aware the error message says 'randomIn()' — this is a source bug, not a different function."],"tags":["pebble-function","randomint","validation","error-message-bug"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}