Skip to content
Latchkey

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.

astro
[InvalidContentEntryFrontmatterError] blog -> post-1.md frontmatter
does not match collection schema.
  pubDate: Required
  title: Expected string, received number

Common 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

  1. Read which entry and field the error names.
  2. Add the missing field or correct its type in that file.
  3. Re-run the build to confirm validation passes.
src/content/blog/post-1.md
---
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.

src/content/config.ts
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.

Frequently asked questions

What causes "Content collection zod error"?
The schema marks a field required (for example pubDate), but an entry omits it, so validation fails.
How do I fix Content collection zod error?
Fix the frontmatter to match the schema

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card