{"record":{"id":"b96e06cbed3a0c2f","repo":"kestra-io/kestra","slug":"chunk-filter-can-only-be-applied-to-list-actual","errorCode":null,"errorMessage":"'chunk' filter can only be applied to List. Actual type was: {}","messagePattern":"'chunk' filter can only be applied to List\\. Actual type was: (.+?)","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/filters/ChunkFilter.java","lineNumber":31,"sourceCode":"public class ChunkFilter implements Filter {\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(\"size\");\n    }\n\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    @Override\n    public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException {\n        if (input == null) {\n            return null;\n        }\n\n        if (!args.containsKey(\"size\")) {\n            throw new PebbleException(null, \"'chunk' filter expects an argument 'size'.\", lineNumber, self.getName());\n        }\n\n        if (!(input instanceof List)) {\n            throw new PebbleException(null, \"'chunk' filter can only be applied to List. Actual type was: \" + input.getClass().getName(), lineNumber, self.getName());\n        }\n\n        Object sizeObj = args.get(\"size\");\n        if (!(sizeObj instanceof Number)) {\n            throw new PebbleException(null, \"'chunk' filter argument 'size' must be a number. Actual type was: \" + sizeObj.getClass().getName(), lineNumber, self.getName());\n        }\n        return Lists.partition((List) input, ((Number) sizeObj).intValue());\n    }\n}\n","sourceCodeStart":13,"sourceCodeEnd":41,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/filters/ChunkFilter.java#L13-L41","documentation":"Thrown by the ChunkFilter when the input to the chunk filter is not a List. The filter can only partition lists into sub-lists; applying it to a string, map, number, or any other type triggers this error.","triggerScenarios":"Calling chunk on a non-list value: '{{ mystring | chunk(2) }}', '{{ mymap | chunk(3) }}', '{{ 42 | chunk(5) }}'. The input variable resolves to a type other than List at runtime.","commonSituations":"A task output that is sometimes a list and sometimes a single object or string, and the template assumes it is always a list. Passing a JSON object (map) where a JSON array (list) was expected.","solutions":["Ensure the input variable is a list before calling chunk: wrap single values with '[...]' or verify the upstream output type.","Use a conditional to handle non-list cases: '{% if myvar is iterable %}{{ myvar | chunk(10) }}{% endif %}'.","Fix the upstream task to always produce a list output."],"exampleFix":"{# before #}\n{{ outputs.task.value | chunk(5) }}\n{# outputs.task.value is a string #}\n\n{# after — ensure list #}\n{{ [outputs.task.value] | chunk(5) }}","handlingStrategy":"type-guard","validationCode":"{# Ensure the input is a list before calling chunk #}\n{% set input = outputs.task.value %}\n{% if input is iterable %}\n  {{ input | chunk(10) }}\n{% else %}\n  {{ [input] | chunk(10) }}\n{% endif %}","typeGuard":"{# Pebble 'is iterable' test narrows to list-like types #}\n{% if myvar is iterable %}\n  {{ myvar | chunk(5) }}\n{% endif %}","tryCatchPattern":null,"preventionTips":["Verify task outputs are typed as arrays (lists) before applying chunk.","Wrap single-value outputs in a list: [value].","Add a conditional type check before calling list-only filters."],"tags":["pebble","chunk-filter","type-mismatch","list"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}