How Validation Works
When you runnpm run build, the prebuild step reads every JSON file in src/data/ and checks each one against its corresponding Zod schema. Zod parses the data strictly: every required field must be present, every value must match its declared type, and any constraints (like URL format or minimum string length) must be satisfied.
If all content passes validation, the build continues. If anything fails, you see a clear error message that names the file, the field, and what was expected — then the build stops. Nothing broken reaches production.
Schema validation also runs in the browser when you save content through Studio. Studio validates your changes against the same schema before sending them to the API, so most errors are caught before they ever reach a build.
Where Schemas Live
Schemas are co-located with the code they describe, making them easy to find when you need to check a field definition.Collection Schemas
Blog post schema (
src/collections/posts/schema.ts) includes fields like:
src/collections/projects/schema.ts) includes fields like:
Section Schemas
Each section type that can appear on a page has its own schema file:/schemas/{slug}.schema.json.
Schema Registry
src/lib/schemas.ts exports a combined registry that maps every slug and section type to its Zod schema. The build pipeline and the Studio editor both use this registry to look up the right schema for any piece of content.
Public JSON Schemas
The Zod schemas are converted to standard JSON Schema format and written topublic/schemas/ at build time. You can access them at:
- External validators and linters
- Agent frameworks that consume JSON Schema contracts
- IDE integrations that support JSON Schema for editing raw data files
- Generating TypeScript types in other projects that consume your portfolio data
How Zod Protects Your Content
Zod catches three broad categories of content mistake before they reach your live site: Missing required fields. If you create a blog post without atitle, Zod throws immediately. You cannot accidentally publish content with blank titles or missing required metadata.
Wrong types. If a project’s year field is written as "2024" (a string) instead of 2024 (a number), Zod catches the mismatch. This is especially common when editing raw JSON files by hand.
Invalid values. Fields with format constraints — like URLs — are checked against those constraints. A broken image URL becomes a build error, not a broken <img> tag.
Reading and Fixing Schema Errors
When a schema validation error occurs during the build, you’ll see output like this:1
Find the file named in the error
The error output tells you which file failed validation. Open that file in your editor — in this example,
src/data/projects/rewrite-2024.json.2
Locate the field named in the path
The
path array in the Zod error shows the field name. Here, ["year"] means the year field on the top-level object is the problem.3
Fix the value to match the expected type
The error says it expected a
number but got a string. Change "year": "2024" to "year": 2024 (remove the quotes) in your JSON file.4
Cross-check with the schema file
If the error message isn’t clear, open the relevant schema file —
src/collections/projects/schema.ts for projects — and read the Zod definition for the failing field to understand exactly what it accepts.5
Re-run the build
Run
npm run build again. If all content now passes validation, the build will continue.Common Errors and Fixes
Generated JSON Schema Files
Thepublic/schemas/ directory contains the JSON Schema equivalents of all your Zod schemas. Like the MCP manifests, these files are generated by the prebuild script and committed to your repository.