What Causes This Error?
This error occurs when the frontmatter in a Markdown file has invalid YAML syntax. Frontmatter must be valid YAML between --- delimiters.
The Problem
---
title: My Post
date: January 15 2024 # ❌ Invalid date format
tags: [one, two # ❌ Missing closing bracket
description: This has: a colon # ❌ Unquoted colon
---
The Fix
Use Valid YAML Syntax
---
title: "My Post"
date: 2024-01-15
tags: [one, two]
description: "This has: a colon"
---
Common Scenarios
Unquoted Special Characters
---
# ❌ Colons need quoting
title: Part 1: The Beginning
# ✅ Quote the string
title: "Part 1: The Beginning"
---
Date Formats
---
# ❌ Invalid date
date: January 15, 2024
# ✅ Valid ISO format
date: 2024-01-15
date: 2024-01-15T10:30:00Z
---
Arrays
---
# ❌ Broken array
tags: [javascript, typescript
# ✅ Valid array
tags: [javascript, typescript]
# Or multiline
tags:
- javascript
- typescript
---
Indentation Issues
---
# ❌ Wrong indentation
author:
name: John # Missing indent
email: john@example.com
# ✅ Proper indentation
author:
name: John
email: john@example.com
---
Boolean Values
---
# ❌ String instead of boolean
draft: "true"
featured: yes
# ✅ YAML booleans
featured: true
---
Multiline Strings
---
# ✅ Literal block (preserves newlines)
description: |
This is a long description
that spans multiple lines.
# ✅ Folded block (joins lines)
summary: >
This will become
one single line.
---
Escaping Quotes
---
# ❌ Unescaped quotes
title: He said "Hello"
# ✅ Escaped or different quotes
title: 'He said "Hello"'
title: "He said \"Hello\""
---
Tab Characters
---
# ❌ Tab characters (invisible but cause errors)
title: "My Post" # Tab before title
# ✅ Use spaces only
title: "My Post" # Spaces
---
Numbers vs Strings
---
# These are numbers
count: 123
price: 19.99
# These are strings
zipcode: "00123" # Leading zero preserved
phone: "+1-555-1234"
---
Validating Frontmatter
# Use a YAML linter
echo "---
title: My Post
tags: [a, b
---" | yq e .
# Online validators
# https://www.yamllint.com/
VS Code Settings
// .vscode/settings.json
{
"yaml.validate": true,
"yaml.schemas": {
"./schema.json": "src/content/**/*.md"
}
}
Checking Error Location
Error: Failed to parse Markdown frontmatter
at src/content/blog/my-post.md
YAMLException: bad indentation of a mapping entry at line 5
→ Check line 5 of the frontmatter
Quick Checklist
- Quote strings with special characters (: # [ ] { })
- Use spaces, not tabs
- Arrays need matching brackets
- Dates in ISO format (YYYY-MM-DD)
- Booleans are
true/false(not quoted) - Check indentation for nested objects