Astro throws “Invalid content entry slug” when a Markdown or MDX entry sets slug in its frontmatter to something that is not a string, such as a number (slug: 2026), a boolean or a list. YAML turns unquoted numbers into numbers, so the fix is usually to quote the value: slug: "2026". In Astro 7 this check runs for legacy content collections; moving the collection to the glob() loader also avoids it.
Key Takeaways
slugmust be a string; YAML readsslug: 2026as a number.- Quote numeric or date-like slugs:
slug: "2026-recap"is safe either way.- The message names the collection and the entry ID, so you know which file to open.
- The check applies to legacy collections (no
loader), enabled withlegacy.collectionsBackwardsCompat.- With
glob(), a frontmatterslugbecomes the entryidand is converted to a string.
The error
Invalid content entry slug.
blog → 2026.md has an invalid slug. `slug` must be a string.
Hint: See https://docs.astro.build/en/guides/content-collections/ for more on the `slug` field.
The first part is the collection, the part after the arrow is the entry.
Why it happens
Legacy content collections let a frontmatter slug override the URL slug Astro generates from the file name. Astro validates that value as a string. YAML decides types from how a value is written:
---
title: "Our year in review"
slug: 2026
---
Here 2026 is a number, so validation fails. The same happens with slug: true, slug: [a, b], or a date such as slug: 2026-01-15, which YAML can parse as a date.
Fix: quote the slug
---
title: "Our year in review"
slug: "2026"
---
Search the collection for other unquoted slugs:
# Terminal
grep -rnE "^slug: [^\"']" src/content/
If the slug just repeats the file name, delete the line; Astro generates the same slug from the file name anyway.
Fix: move to the glob() loader
In Astro 7, collections without a loader only work with the legacy flag. Moving to the Content Layer is the long-term fix:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
schema: z.object({ title: z.string() }),
});
export const collections = { blog };
With glob(), a frontmatter slug sets the entry’s id, and Astro converts it to a string, so slug: 2026 becomes the ID "2026". Your pages then use post.id instead of post.slug. The legacy content config fix covers the migration, and our content collections guide explains IDs and routes. Do not add slug to your schema; that triggers a different error, covered in schema contains slug.
See the content collections docs for a full config. Themes in the Blog & Editorial category already use the glob() loader.
FAQ
What is the slug field in Astro content collections?
An optional frontmatter value that overrides the URL segment Astro generates from the file name. With the glob() loader it sets the entry id; in legacy collections it sets slug.
Why is my numeric slug invalid in Astro?
YAML parses unquoted numbers as numbers, and legacy collections require slug to be a string. Wrap it in quotes.
Do I still need slug in Astro 7?
Usually not. Name the file the way you want the URL to read, and use post.id in your routes. Use slug only when the URL must differ from the file name.