{"record":{"id":"4d5c6b490dd9f728","repo":"BerriAI/litellm","slug":"invalid-yaml-frontmatter-e","errorCode":null,"errorMessage":"Invalid YAML frontmatter: {e}","messagePattern":"Invalid YAML frontmatter: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/dotprompt/prompt_manager.py","lineNumber":175,"sourceCode":"            content=template_content.strip(),\n            metadata=frontmatter,\n            template_id=prompt_id,\n        )\n\n    def _parse_frontmatter(self, content: str) -> tuple[dict[str, Any], str]:\n        \"\"\"Parse YAML frontmatter from prompt content.\"\"\"\n        # Match YAML frontmatter between --- delimiters\n        frontmatter_pattern: Final = r\"^---\\s*\\n(.*?)\\n---\\s*\\n(.*)$\"\n        match: Final = re.match(frontmatter_pattern, content, re.DOTALL)\n\n        if match:\n            frontmatter_yaml: Final = match.group(1)\n            template_content = match.group(2)\n\n            try:\n                frontmatter = yaml.safe_load(frontmatter_yaml) or {}\n            except yaml.YAMLError as e:\n                raise ValueError(f\"Invalid YAML frontmatter: {e}\")\n        else:\n            # No frontmatter found, treat entire content as template\n            frontmatter = {}\n            template_content = content\n\n        return frontmatter, template_content\n\n    def render(\n        self,\n        prompt_id: str,\n        prompt_variables: dict[str, Any] | None = None,\n        version: int | None = None,\n    ) -> str:\n        \"\"\"\n        Render a prompt template with the given variables.\n\n        Args:\n            prompt_id: The ID of the prompt template to render","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/dotprompt/prompt_manager.py#L157-L193","documentation":"While loading a .prompt file, _parse_frontmatter runs re.match for the leading '---' delimiters and feeds the captured block to yaml.safe_load; any YAML syntax error is re-raised as ValueError('Invalid YAML frontmatter: ...'). Only YAML errors are wrapped here — structural issues (no delimiters) instead fall through to 'entire content is template'.","triggerScenarios":"A .prompt file whose frontmatter contains tab indentation, an unquoted colon inside a value, unclosed quotes/brackets, or duplicate keys. Editing prompts by hand or generating them from templates that mangle whitespace. Loading via prompt_directory, where this error surfaces during __init__ — but note the directory loader catches per-file exceptions silently, so via a directory this instead manifests later as 'Prompt ... not found'; via prompt_file it propagates.","commonSituations":"Copy-pasting frontmatter from docs that converted spaces to tabs; question-style default values ('question: What: is your name?'); YAML treating 'no'/'on' as booleans only after other syntax broke; editors auto-stripping trailing spaces inside the block.","solutions":["Run yaml.safe_load on the text between the '---' lines in isolation to reproduce and see the exact parser message","Fix indentation to spaces only, and quote any value containing a colon or special character","Validate prompt files in CI with a small script that parses each file's frontmatter","If loading via prompt_directory, remember failures are swallowed — check manager.prompts.keys() after init to confirm the file actually registered"],"exampleFix":"# before — prompts/greeting.prompt\n---\nname: greeting\nquestion: What: is your name?\n---\nHello {{user}}\n\n# after\n---\nname: greeting\nquestion: \"What: is your name?\"\n---\nHello {{user}}","handlingStrategy":"try-catch","validationCode":"import re, yaml\n\ndef validate_prompt_file(path):\n    text = Path(path).read_text()\n    m = re.match(r'^---\\s*\\n(.*?)\\n---\\s*\\n(.*)$', text, re.DOTALL)\n    if m:\n        yaml.safe_load(m.group(1))  # raises YAMLError with position info\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    template = manager._load_prompt_file(path, prompt_id)\nexcept ValueError as e:\n    if 'Invalid YAML frontmatter' in str(e):\n        logger.error('frontmatter syntax error in %s: %s', path, e)\n        raise","preventionTips":["Lint all .prompt frontmatter in CI with yaml.safe_load","Configure editors to use spaces (never tabs) in .prompt files","Quote frontmatter values containing colons or special characters"],"tags":["litellm","dotprompt","prompt","yaml","frontmatter","config-parse"],"backgroundTag":"yaml-parse-error","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}