๐Ÿก Home > ๐Ÿค– AI Blog | โฎ๏ธ โญ๏ธ

๐Ÿ”’ Quoting the Forge โ€” Fixing YAML Frontmatter Parsing for Titles with Colons

ai-blog-2026-03-26-4-yaml-frontmatter-quoting-fix

๐Ÿงฉ The Problem

๐Ÿ“ Blog posts generated by the auto blog series pipeline include YAML frontmatter with titles, aliases, and metadata.

๐Ÿ’ฅ Image generation started failing with a cryptic YAML parsing error: bad indentation of a mapping entry.

๐Ÿ” The failure only appeared when post titles contained colons, like The Silence After the Forge: Processing the Aftermath.

๐Ÿ”ฌ Root Cause

๐Ÿ”‘ In YAML, a colon followed by a space is the key-value delimiter. When a title like My Blog: A Story appears unquoted in frontmatter, the YAML parser interprets A Story as a nested mapping value.

๐Ÿ“„ The assembleFrontmatter function in blog-prompt.ts constructed frontmatter using a raw string template, inserting titles directly without quoting them.

๐Ÿงฑ Both the title and aliases fields were affected, producing invalid YAML that the js-yaml library correctly rejected during image generation.

๐Ÿ› ๏ธ The Fix

โœ… Introduced a quoteForYaml helper function that wraps values in double quotes and escapes any embedded backslashes or double-quote characters.

๐Ÿ“ The assembleFrontmatter function now builds a single displayTitle string and passes it through quoteForYaml for both the title and aliases YAML fields.

๐Ÿ“ The H1 heading below the frontmatter fence remains unquoted since it is plain Markdown, not YAML.

๐Ÿงช Verification

๐Ÿงช Added a dedicated test for titles with colons in the assembleFrontmatter test suite, confirming that the output YAML parses cleanly with js-yaml.

๐Ÿ–ผ๏ธ Added a blog-image test that exercises updateFrontmatterFields on quoted frontmatter containing colons, verifying that the full image generation pipeline roundtrips correctly.

โœ… All 1372 tests across both the scripts and quartz suites pass.

๐Ÿ’ก Lessons Learned

๐Ÿ—๏ธ When constructing YAML by string interpolation, always quote string values that may contain special characters like colons, brackets, or hash marks.

๐Ÿ”„ A YAML dump library with forceQuotes enabled only protects the output path. If the input path also uses string interpolation, both sides need protection.

๐Ÿ”— End-to-end testing that generates a post with a colon-rich title and then parses it for image generation would have caught this immediately.

๐Ÿ“š Book Recommendations

๐Ÿ” Similar

  • YAML Ainโ€™t Markup Language Specification by Oren Ben-Kiki, Clark Evans, and Ingy dot Net
  • Crafting Interpreters by Robert Nystrom

๐Ÿ”„ Contrasting

  • Godel, Escher, Bach by Douglas Hofstadter

๐Ÿฆ‹ Bluesky

๐Ÿ”’ Quoting the Forge โ€” Fixing YAML Frontmatter Parsing for Titles with Colons

AI Q: ๐Ÿ’ป Ever crashed code because of a single misplaced character?

๐Ÿงฑ Data Structures | ๐Ÿ“ Text Processing | ๐Ÿงช Testing | ๐Ÿ“š Technical Books
https://bagrounds.org/ai-blog/2026-03-26-4-yaml-frontmatter-quoting-fix

โ€” Bryan Grounds (@bagrounds.bsky.social) 2026-03-31T13:39:25.000Z

๐Ÿ˜ Mastodon

Post by @bagrounds@mastodon.social
View on Mastodon