{"record":{"id":"d51de1b99a122bb8","repo":"kestra-io/kestra","slug":"invalid-yaml-s","errorCode":null,"errorMessage":"Invalid yaml: %s","messagePattern":"Invalid yaml: (.+?)","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/YamlFunction.java","lineNumber":49,"sourceCode":"        return Map.of(\"yaml\", \"inputs.yamlInput\");\n    }\n\n    @Override\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        if (!args.containsKey(\"yaml\")) {\n            throw new PebbleException(null, \"The 'yaml' function expects an argument 'yaml'.\", lineNumber, self.getName());\n        }\n\n        if (!(args.get(\"yaml\") instanceof String)) {\n            throw new PebbleException(null, \"The 'yaml' function expects an argument 'yaml' with type string.\", lineNumber, self.getName());\n        }\n\n        String yaml = (String) args.get(\"yaml\");\n\n        try {\n            return MAPPER.readValue(yaml, TYPE_REFERENCE);\n        } catch (JacksonYAMLParseException e) {\n            throw new PebbleException(null, \"Invalid yaml: \" + e.getMessage(), lineNumber, self.getName());\n        } catch (JsonMappingException e) {\n            throw new PebbleException(null, \"Invalid yaml: \" + e.getMessage(), lineNumber, self.getName());\n        } catch (JsonProcessingException e) {\n            throw new PebbleException(null, \"Invalid yaml: \" + e.getMessage(), lineNumber, self.getName());\n        }\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":57,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/YamlFunction.java#L31-L57","documentation":"The `yaml()` function delegates to Jackson's YAML parser (`ObjectMapper.readValue`). If the input string is not valid YAML, the parser throws `JacksonYAMLParseException`, `JsonMappingException`, or `JsonProcessingException`, all of which are caught and re-thrown as a `PebbleException` with the prefix 'Invalid yaml:'. The original parser error message is appended.","triggerScenarios":"Passing a YAML string with malformed syntax: wrong indentation, unbalanced brackets, tab characters, or unquoted special characters. Passing content that is valid in one format but not YAML (e.g., raw JSON with comments).","commonSituations":"A user concatenates YAML fragments with string operations that introduce whitespace or indentation errors. Tabs are used instead of spaces for indentation. A multi-line input field contains stray characters.","solutions":["Validate the YAML string in an external linter before passing it to the function.","Check indentation: YAML requires spaces, never tabs, and consistent indent levels.","Quote scalar values containing special characters (`:`, `{`, `[`, `#`, etc.).","Use the error message's line reference (when available) to locate the syntax issue."],"exampleFix":"# before\n{{ yaml(inputs.yamlInput) }}\n# where inputs.yamlInput contains:\n# key1: value1\n# \tkey2: value2   <- tab character\n# after (fix indentation to spaces)\n# key1: value1\n# key2: value2","handlingStrategy":"try-catch","validationCode":"// Pre-validate YAML with Jackson before passing to Pebble template\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.fasterxml.jackson.dataformat.yaml.YAMLFactory;\n\nObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());\npublic static boolean isValidYaml(String input) {\n    try {\n        yamlMapper.readTree(input);\n        return true;\n    } catch (Exception e) {\n        return false;\n    }\n}","typeGuard":null,"tryCatchPattern":"// In Java code that builds templates with dynamic YAML\ntry {\n    String result = pebbleTemplate.evaluate(context);\n} catch (PebbleException e) {\n    if (e.getMessage().startsWith(\"Invalid yaml:\")) {\n        log.warn(\"YAML parsing failed in template: {}\", e.getMessage());\n        // provide fallback or user-facing error\n    } else {\n        throw e;\n    }\n}","preventionTips":["Validate YAML content with an external linter before storing it in a variable.","Never use tabs for YAML indentation — always use spaces.","Quote scalars that contain special characters (:, #, {, }, [, ]).","Test multi-line YAML inputs in isolation before embedding them in a flow."],"tags":["pebble","yaml","parsing-error","jackson"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}