{"record":{"id":"f2b268c6b7ae4e8e","repo":"kestra-io/kestra","slug":"the-substringbeforelast-filter-expects-an-argume","errorCode":null,"errorMessage":"The 'substringBeforeLast' filter expects an argument 'separator'.","messagePattern":"The 'substringBeforeLast' filter expects an argument 'separator'\\.","errorType":"validation","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/filters/SubstringBeforeLastFilter.java","lineNumber":33,"sourceCode":"    private final List<String> argumentNames = new ArrayList<>();\n\n    public SubstringBeforeLastFilter() {\n        this.argumentNames.add(\"separator\");\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return this.argumentNames;\n    }\n\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(\"separator\")) {\n            throw new PebbleException(\n                null,\n                \"The 'substringBeforeLast' filter expects an argument 'separator'.\",\n                lineNumber,\n                self.getName()\n            );\n        }\n\n        String separator = (String) args.get(\"separator\");\n        ;\n\n        return StringUtils.substringBeforeLast(input.toString(), separator);\n    }\n}\n","sourceCodeStart":15,"sourceCodeEnd":47,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/filters/SubstringBeforeLastFilter.java#L15-L47","documentation":"The 'substringBeforeLast' filter returns the substring before the LAST occurrence of a separator (StringUtils.substringBeforeLast). It declares 'separator' as a required named argument and throws a PebbleException if args does not contain it when apply() runs.","triggerScenarios":"Writing {{ dir | substringBeforeLast }} when the intent was {{ dir | substringBeforeLast(separator=\"/\") }} (e.g. to drop the last path segment). Also when the separator expression evaluates to null.","commonSituations":"Path manipulation where the last segment must be removed; forgetting the argument; separator variable undefined after an upstream task produced no output.","solutions":["Add the separator argument: {{ dir | substringBeforeLast(separator=\"/\") }}.","Confirm the separator variable is defined and non-null.","Test the expression in the Kestra expression editor before committing it to the flow."],"exampleFix":"// before\n{{ outputs.path | substringBeforeLast }}\n// after\n{{ outputs.path | substringBeforeLast(separator=\"/\") }}","handlingStrategy":"validation","validationCode":"{{ myVar is empty ? '' : myVar | substringBeforeLast(separator=(mySep ?? \"/\")) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass separator explicitly.","Ensure the feeding variable is non-null.","Test the filter call in the expression editor."],"tags":["pebble","template","filter","argument"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}