kestra-io/kestra · error · PebbleException

Input must be a list, but received : {}

Error message

Input must be a list, but received : {}

What it means

Thrown by the DistinctFilter when the input is not null but is not a List. The distinct filter deduplicates list elements using stream().distinct(); it cannot operate on strings, maps, numbers, or other types.

Source

Thrown at core/src/main/java/io/kestra/core/runners/pebble/filters/DistinctFilter.java:36

    @Override
    public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context,
        int lineNumber) throws PebbleException {

        if (input == null) {
            return "null";
        }

        // Check if the input is a list
        if (input instanceof List<?>) {
            List<?> list = (List<?>) input;

            // Deduplicate the list by using distinct stream operation
            return list.stream().distinct().collect(Collectors.toList());
        }

        //if the input is not list, throwing exception with constructor
        throw new PebbleException(
            null,
            "Input must be a list, but received : " + (input != null ? input.getClass().getName() : "null"),
            lineNumber,
            self != null ? self.getName() : "Unknown"
        );
    }
}

View on GitHub (pinned to 823fada927)

Solutions

  1. Ensure the input is a list before calling distinct.
  2. Wrap single values in a list if needed: '{{ [myvalue] | distinct }}'.
  3. Add a type check or conditional before applying the filter.

Example fix

{# before #}
{{ outputs.task.value | distinct }}
{# outputs.task.value is a string #}

{# after — ensure list #}
{{ [outputs.task.value] | distinct }}
Defensive patterns

Strategy: type-guard

Validate before calling

{# Ensure the input is a list before calling distinct #}
{% set input = outputs.task.value %}
{% if input is iterable %}
  {{ input | distinct }}
{% else %}
  {{ [input] | distinct }}
{% endif %}

Type guard

{# Pebble 'is iterable' narrows to list-like types #}
{% if myvar is iterable %}
  {{ myvar | distinct }}
{% endif %}

Prevention

When it happens

Trigger: Calling distinct on a non-list value: '{{ mystring | distinct }}', '{{ mymap | distinct }}', '{{ 42 | distinct }}'. The input variable resolves to a type other than List at runtime.

Common situations: A task output that is sometimes a list and sometimes a single scalar. Passing a JSON object where a JSON array was expected. Template logic that assumes an output is always a collection.

Related errors


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