kestra-io/kestra · error · PebbleException

In 'randomIn()' upper is less than lower

Error message

In 'randomIn()' upper is less than lower

What it means

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.

Source

Thrown at core/src/main/java/io/kestra/core/runners/pebble/functions/RandomIntFunction.java:19

package io.kestra.core.runners.pebble.functions;

import java.util.List;
import java.util.Map;

import io.pebbletemplates.pebble.error.PebbleException;
import io.pebbletemplates.pebble.template.EvaluationContext;
import io.pebbletemplates.pebble.template.PebbleTemplate;

public class RandomIntFunction implements KestraFunction {
    public static final String NAME = "randomInt";

    @Override
    public Object execute(
        Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
        Long lower = getArgument(args, "lower", self, lineNumber);
        Long upper = getArgument(args, "upper", self, lineNumber);
        if (upper < lower) {
            throw new PebbleException(
                null,
                "In 'randomIn()' upper is less than lower",
                lineNumber,
                self.getName()
            );
        }
        return (int) (Math.floor(Math.random() * (upper - lower)) + lower);
    }

    @Override
    public List<String> getArgumentNames() {
        return List.of("lower", "upper");
    }

    @Override
    public Map<String, String> getArgumentDefaults() {
        return Map.of("lower", "0", "upper", "10");
    }

View on GitHub (pinned to 823fada927)

Solutions

  1. Ensure upper >= lower: {{ randomInt(lower=5, upper=10) }}.
  2. If bounds are dynamic, swap them when needed: {% set lo = min(a, b) %}{% set hi = max(a, b) %}{{ randomInt(lower=lo, upper=hi) }}.
  3. Be aware the error text references 'randomIn()' — this is a known message bug, not a different function.

Example fix

# before
value: "{{ randomInt(lower=10, upper=5) }}"
# after
value: "{{ randomInt(lower=5, upper=10) }}"
Defensive patterns

Strategy: validation

Validate before calling

# Ensure upper >= lower before calling randomInt:
{% set lo = min(lowerVal, upperVal) %}
{% set hi = max(lowerVal, upperVal) %}
{{ randomInt(lower=lo, upper=hi) }}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


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