---
title: "Schemas"
description: "How entries are validated and what qino adds or reserves."
canonical: "https://www.qino.works/docs/concepts/schemas"
---

# Schemas

> How entries are validated and what qino adds or reserves.

Every primitive takes a `schema`. qino accepts any [Standard Schema](https://standardschema.dev) validator and treats it as a black box: it calls the standard validate function and never touches validator-specific APIs. Zod, Valibot, and ArkType all work.

The schema must be synchronous. A validator that returns a Promise is rejected.

With [`cloud`](https://www.qino.works/docs/guide/cloud) set, the schema must also implement [Standard JSON Schema](https://standardschema.dev/json-schema), so it can be converted to JSON Schema. Not every Standard Schema validator does.

## What the schema receives

For Markdown, MDX, and `.markdown` files, the input is the parsed frontmatter only:

```ts title="Schema input for hello-world.md"
{
  title: "Hello",
  draft: false,
}
```

For `.json` files, the input is the parsed object as-is.

A file without frontmatter validates `{}`, so an empty schema like `z.object({})` is enough. Schemas are required even then.

To reshape data, such as splitting a string or renaming keys, use your validator's transform. See [Transforming data](https://www.qino.works/docs/concepts/pipeline#transforming-data).

## markdown

After validation, qino adds the body to every Markdown entry as `markdown`, a string without the frontmatter, like it adds `_meta`. An empty body is an empty string.

```ts title="Entry for hello-world.md"
{
  title: "Hello",
  draft: false,
  markdown: "The body, without frontmatter.",
  _meta: { slug: "hello-world", fileName: "hello-world.md", filePath: "/abs/path/posts/hello-world.md" },
}
```

Don't declare it in the schema: the schema never sees it, so strict objects work as-is. It is added before views run, so `augment`, `filter`, and `sort` can read it. To derive something from the body, use [`augment`](https://www.qino.works/docs/concepts/views). For word and character counts, set `markdown: { stats: true }` and qino adds a `_stats` field too. See [MarkdownStats](https://www.qino.works/docs/api/types/markdown-stats). For a table of contents, set `markdown.toc` and qino adds a `_toc` field. See [MarkdownToc](https://www.qino.works/docs/api/types/markdown-toc). For a page's Markdown to copy or serve, with a title heading and absolute links, use [getPageMarkdown](https://www.qino.works/docs/api/collection/get-page-markdown).

In Markdown files, `markdown`, `_stats`, and `_toc` are reserved at the top level of frontmatter, schema input, and schema output. Declaring them in a schema is a type error, and frontmatter or a transform that introduces them fails at runtime. Augment callbacks cannot add or replace `markdown`, nor `_stats` when `markdown.stats` is on, nor `_toc` when `markdown.toc` is on. In JSON files, they are ordinary fields.

## Reserved: \_meta

`_meta` is reserved at the top level of content, schema input, and schema output, for every format. Declaring it in a schema is a type error. A transform that introduces it fails at runtime. Nested keys named `_meta` are ordinary fields.

After validation, qino adds `_meta`:

| Primitive  | `_meta` fields                 |
| ---------- | ------------------------------ |
| Collection | `slug`, `fileName`, `filePath` |
| Tree       | `slug`, `fileName`, `filePath` |
| Item       | `fileName`, `filePath`         |

## Dates

YAML never produces `Date` objects on its own. Validate date strings with `z.iso.date()` or coerce with `z.coerce.date()`. See [Frontmatter](https://www.qino.works/docs/guide/frontmatter).

## Validation errors

A failing entry throws with the file path and every issue:

```txt title="Terminal"
Validation failed for /abs/path/posts/hello.md:
  title: Invalid input: expected string, received undefined
```

`qino check` runs the same validation for every file. See [CLI](https://www.qino.works/docs/guide/cli).
