Astro content collection schema (zod) validation failed in CI
Astro content collections validate each entry's frontmatter against a zod schema defined in src/content/config.ts. If a required field is missing or a type is wrong, the build fails validation and names the entry and field. This often passes locally when a bad file was uncommitted.
What this error means
The build fails with a content-collection error citing a zod issue such as "Required" or "Expected string, received number" for a specific entry and field.
[InvalidContentEntryFrontmatterError] blog -> post-1.md frontmatter
does not match collection schema.
pubDate: Required
title: Expected string, received numberCommon causes
Frontmatter missing a required field
The schema marks a field required (for example pubDate), but an entry omits it, so validation fails.
A frontmatter value of the wrong type
A field is a number, string, or bad date where the schema expects another type, or a date string zod cannot coerce.
How to fix it
Fix the frontmatter to match the schema
- Read which entry and field the error names.
- Add the missing field or correct its type in that file.
- Re-run the build to confirm validation passes.
---
title: "My Post"
pubDate: 2026-06-30
---Relax or coerce the schema where appropriate
If a field is genuinely optional, mark it .optional(); for dates, use z.coerce.date() so string dates parse.
import { z, defineCollection } from "astro:content";
const blog = defineCollection({
schema: z.object({ title: z.string(), pubDate: z.coerce.date() }),
});How to prevent it
- Keep the zod schema and real frontmatter in sync.
- Use
z.coerce.date()for date frontmatter. - Run the build in CI so schema drift fails fast.