{"record":{"id":"c67efba2d62269f4","repo":"kestra-io/kestra","slug":"the-yaml-function-expects-an-argument-yaml-wit","errorCode":null,"errorMessage":"The 'yaml' function expects an argument 'yaml' with type string.","messagePattern":"The 'yaml' function expects an argument 'yaml' with type string\\.","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/YamlFunction.java","lineNumber":41,"sourceCode":"    };\n\n    public List<String> getArgumentNames() {\n        return List.of(\"yaml\");\n    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        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":23,"sourceCodeEnd":57,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/YamlFunction.java#L23-L57","documentation":"The `yaml()` function's `yaml` argument must be a `String`. If the argument is present but its runtime type is not `String` (e.g., a Map, List, Number, or Boolean resolved from Pebble), a `PebbleException` is thrown. The function only parses string-serialized YAML.","triggerScenarios":"Passing a variable that is already a parsed object (Map/List) rather than a raw YAML string. Passing a numeric or boolean literal.","commonSituations":"A flow input typed as YAML/JSON is automatically parsed by Kestra before reaching the template, so the variable is already a Map, not a string. The developer expects `yaml()` to handle an already-parsed object.","solutions":["Ensure the argument is a raw YAML string, not a pre-parsed object.","If the input is already structured, do not use `yaml()` — use it directly.","If the input is a string-typed flow input containing YAML text, verify it has not been auto-parsed by changing the input type to `STRING`."],"exampleFix":"# before (inputs.yamlInput is type YAML, auto-parsed to a Map)\n{{ yaml(inputs.yamlInput) }}\n# after (change input type to STRING so it stays raw text)\nid: yamlInput\ntype: STRING","handlingStrategy":"type-guard","validationCode":"# Ensure the flow input that feeds yaml() is typed as STRING, not YAML/JSON\nid: yamlInput\ntype: STRING\n# Then in template:\n{{ yaml(inputs.yamlInput) }}","typeGuard":"// Type guard: check if value is a string before calling yaml()\nfunction isString(v: unknown): v is string {\n    return typeof v === 'string';\n}","tryCatchPattern":null,"preventionTips":["Use STRING input type for content that must be parsed by yaml().","Avoid passing already-parsed YAML/JSON objects to yaml().","If the data is already structured, use it directly without yaml()."],"tags":["pebble","yaml","type-error","validation"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}