kestra-io/kestra · error · PebbleException

The 'randomIn()' function expects an argument %s of type Lon

Error message

The 'randomIn()' function expects an argument %s of type Long.

What it means

The randomInt(lower, upper) function checks that each argument value is an instance of Long. Pebble evaluates numeric literals as Long, so this fires when a non-numeric type is passed — a String, a Float/Double, or a Boolean. Note: the error message incorrectly references 'randomIn()' instead of 'randomInt()', and uses %s-style formatting with string concatenation.

Source

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

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

    private Long getArgument(
        Map<String, Object> args, String arg, PebbleTemplate self, int lineNumber) {
        if (!args.containsKey(arg)) {
            throw new PebbleException(
                null,
                "The 'randomIn()' function expects an argument " + arg,
                lineNumber,
                self.getName()
            );
        }

        if (!(args.get(arg) instanceof Long)) {
            throw new PebbleException(
                null,
                "The 'randomIn()' function expects an argument " + arg + " of type Long.",
                lineNumber,
                self.getName()
            );
        }
        return (Long) args.get(arg);
    }
}

View on GitHub (pinned to 823fada927)

Solutions

  1. Pass integer literals (Pebble evaluates them as Long): {{ randomInt(lower=0, upper=10) }}.
  2. If the value comes from a variable that might be a string, convert it in the expression or ensure the upstream task outputs a numeric type.
  3. Avoid decimal values — randomInt operates on integer ranges only.

Example fix

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

Strategy: type-guard

Validate before calling

# Ensure arguments are integers (Long), not strings or decimals:
{{ randomInt(lower=0, upper=10) }}
# If from a variable, ensure it is numeric and integer-valued:
{% if lowerVar is number and upperVar is number %}
  {{ randomInt(lower=lowerVar, upper=upperVar) }}
{% endif %}

Type guard

# Pebble type test for numeric values:
{% if myVar is number %}...{% endif %}

Prevention

When it happens

Trigger: Passing a string: {{ randomInt(lower='0', upper='10') }}. Passing a float/double: {{ randomInt(lower=0.5, upper=10.5) }}. Passing a variable that holds a non-Long type.

Common situations: YAML values that Pebble evaluates as strings rather than numbers. An upstream task output provides a string representation of a number instead of a numeric type. The author passes a decimal where an integer is expected.

Related errors


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