haystack icon indicating copy to clipboard operation
haystack copied to clipboard

`FileSystemSkillStore` reports a missing `description` for a `SKILL.md` that starts with a UTF-8 BOM

Open Assertive-xxh opened this issue 3 weeks ago • 0 comments

Describe the bug FileSystemSkillStore does not recognize the frontmatter of a SKILL.md that starts with a UTF-8 byte order mark (BOM). warm_up() raises a ValueError saying the skill is missing a description, although the file has one. The BOM is invisible in most editors, so the message points the user in the wrong direction. Because warm_up() validates every skill, one such file stops the whole skills directory from loading, and SkillToolset.warm_up() fails with the same error.

The store reads files with encoding="utf-8", which keeps the BOM as a leading U+FEFF. _parse_frontmatter calls text.lstrip() and then checks that the first line is ---. str.lstrip() does not treat U+FEFF as whitespace, so the first line is --- and the file is handled as if it had no frontmatter.

read_skill_file has the same cause and a milder effect: a bundled text file saved with a BOM is returned with a leading , which ends up in the tool result.

Error message

ValueError: Skill 'pdf-forms' (<tmp>/pdf-forms/SKILL.md) is missing a 'description' in its frontmatter.

Expected behavior A leading BOM is ignored: the skill is listed with its description, load_skill returns the body, and read_skill_file returns the text without .

Additional context

  • Where such files come from: Windows PowerShell 5.1 writes a BOM with -Encoding UTF8 (docs), and editors such as Notepad and VS Code offer "UTF-8 with BOM" when saving. The behavior itself is not OS-specific. It depends only on the bytes of the file, and I reproduced it on Linux.
  • #12726 fixed the same problem for the text, CSV, Markdown and JSON converters by reading with utf-8-sig. The skill store was not part of that change.
  • Other skill loaders handle this case. For example, Crush strips a leading BOM before it splits the frontmatter (skills.go).
  • I searched open and closed issues and pull requests for "BOM", "byte order mark", "utf-8-sig", "frontmatter" and "FileSystemSkillStore" and found nothing about this.
  • I have a small fix with regression tests ready (read SKILL.md and bundled text files with utf-8-sig) and would like to open a pull request for it. Please let me know if you would rather handle this internally or prefer a different approach.
  • AI disclosure: I used an AI assistant to find and analyze this and to draft the report. The reproduction below was run against main, and I have checked the output.

To Reproduce

import tempfile
from pathlib import Path

from haystack.skill_stores.file_system import FileSystemSkillStore

SKILL_MD = "---\nname: pdf-forms\ndescription: Fill PDF forms.\n---\nUse the form filler.\n"

with tempfile.TemporaryDirectory() as tmp:
    skill_dir = Path(tmp) / "pdf-forms"
    skill_dir.mkdir()
    # "utf-8-sig" writes a leading UTF-8 byte order mark (EF BB BF)
    (skill_dir / "SKILL.md").write_text(SKILL_MD, encoding="utf-8-sig")
    (skill_dir / "fields.md").write_text("Field reference.\n", encoding="utf-8-sig")

    try:
        print(FileSystemSkillStore(tmp).list_skills())
    except ValueError as error:
        print("ValueError:", error)

    # Rewrite SKILL.md without a BOM so the store loads; the bundled file still has one.
    (skill_dir / "SKILL.md").write_text(SKILL_MD, encoding="utf-8")
    print(repr(FileSystemSkillStore(tmp).read_skill_file("pdf-forms", "fields.md")))

Output on main (4b4346b):

ValueError: Skill 'pdf-forms' (<tmp>/pdf-forms/SKILL.md) is missing a 'description' in its frontmatter.
'Field reference.\n'

Expected output:

{'pdf-forms': SkillInfo(name='pdf-forms', description='Fill PDF forms.')}
'Field reference.\n'

FAQ Check

System:

  • OS: Ubuntu 24.04 (WSL2 on Windows 11), Python 3.12.3
  • Haystack version: main at 4b4346b (3.6.0-rc0). v3.5.0 has the same code in skill_store.py; I did not run it there.

Assertive-xxh avatar Nov 14 '26 03:11 Assertive-xxh