Skip to content

Add llms.txt #4915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions packages/docs/app/(doc)/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Callout } from "fumadocs-ui/components/callout";
import defaultMdxComponents, { createRelativeLink } from "fumadocs-ui/mdx";
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from "fumadocs-ui/page";
import { notFound } from "next/navigation";
import { Github } from "lucide-react";

export const revalidate = 86400;

Expand All @@ -25,37 +26,46 @@ export default async function Page(props: {
return item;
});

const editOnGithub = (
<h3 className=" pt-3 mt-3 inline-flex items-center gap-1.5 text-sm text-fd-muted-foreground">
<a
href={`https://github.com/colinhacks/zod/blob/main/content/packages/docs/${page.file.path}`}
rel="noreferrer noopener"
target="_blank"
className="text-gray-500 hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-300 text-sm no-underline"
>
<Github className="w-4 h-4 inline mr-[1px]" /> Edit this page
</a>
</h3>
)

return (
<DocsPage
toc={toc}
tableOfContent={{ style: "clerk", single: false }}
tableOfContent={{ style: "clerk", single: false, footer: editOnGithub }}
full={false}
editOnGithub={{
owner: "colinhacks",
repo: "zod",
sha: "main",
path: `packages/docs/content/${page.file.path}`,
}}

>
{title && title !== "Intro" ? <DocsTitle>{title}</DocsTitle> : null}
<DocsDescription>{description}</DocsDescription>
{/* <DocsDescription>{description}</DocsDescription> */}
<DocsBody {...{}}>
<MDXContent
components={{
...defaultMdxComponents,
// this allows you to link to other pages with relative file paths
a: createRelativeLink(source, page),
// you can add other MDX components here
blockquote: Callout,
Tabs,
h1: (props: any) => <Heading as="h1" {...props} />,
h2: (props: any) => <Heading as="h2" {...props} />,
h3: (props: any) => <Heading as="h3" {...props} />,
h4: (props: any) => <Heading as="h4" {...props} />,
h5: (props: any) => <Heading as="h5" {...props} />,
h6: (props: any) => <Heading as="h6" {...props} />,
}}
/>
<MDXContent
components={{
...defaultMdxComponents,
// this allows you to link to other pages with relative file paths
a: createRelativeLink(source, page),
// you can add other MDX components here
blockquote: Callout,
Tabs,
h1: (props) => <Heading as="h1" {...props} />,
h2: (props) => <Heading as="h2" {...props} />,
h3: (props) => <Heading as="h3" {...props} />,
h4: (props) => <Heading as="h4" {...props} />,
h5: (props) => <Heading as="h5" {...props} />,
h6: (props) => <Heading as="h6" {...props} />,
}}

/>
</DocsBody>
</DocsPage>
);
Expand Down
99 changes: 99 additions & 0 deletions packages/docs/app/llms.txt/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { source } from "@/loaders/source";

// cached forever
export const revalidate = false;

function stringifyTitle(title: any): string {
if (typeof title === "string") return title;
if (typeof title === "number" || typeof title === "bigint" || typeof title === "boolean") {
return String(title);
}

// Handle React elements and complex objects
if (title && typeof title === "object") {
// If it's a React element with props.children
if (title.props?.children) {
return stringifyTitle(title.props.children);
}

// If it's an array, join the elements
if (Array.isArray(title)) {
return title.map(stringifyTitle).join("");
}

// If it has a textContent property
if (title.textContent) {
return String(title.textContent);
}

// Try to extract text from common React element patterns
if (title.type && (title.type === "span" || title.type === "code" || typeof title.type === "string")) {
if (typeof title.props?.children === "string") {
return title.props.children;
}
}
}

return "";
}

export async function GET() {
const pages = source.getPages();

// Generate LLMS.txt content
let txt = `# Zod

> Zod is a TypeScript-first schema validation library with static type inference. This documentation provides comprehensive coverage of Zod 4's features, API, and usage patterns.

`;

// Process each page
for (const page of pages) {
// Skip separator entries that start with "---"
const title = stringifyTitle(page.data.title);
if (title.startsWith("---")) {
continue;
}

// Create section for each page
txt += `## ${title || "Untitled"}\n\n`;

// Add main page link with description from frontmatter
const pageUrl = `https://zod.dev${page.url}`;
const description = page.data.description || "Documentation page";
txt += `- [${title || "Untitled"}](${pageUrl}): ${description}\n`;

// Add TOC sections for deep linking
if (page.data.toc && page.data.toc.length > 0) {
// Group sections by depth for better organization
const sections = page.data.toc.filter((item: any) => item.depth >= 2 && item.depth <= 4);

if (sections.length > 0) {
txt += "\n";

for (const section of sections) {
const sectionTitle = stringifyTitle(section.title);
if (!sectionTitle) continue;

const anchor = section.url.replace("#", "");
const fullUrl = `https://zod.dev${page.url}?id=${anchor}`;

txt += `- [${sectionTitle}](${fullUrl})\n`;
}
}
}

txt += "\n";
}

txt += `---

This documentation covers Zod v4, a TypeScript-first schema validation library. Use the URLs above to access specific pages and sections for detailed information about schema definition, validation, error handling, and advanced patterns.
`;

return new Response(txt, {
headers: {
"Content-Type": "text/plain; charset=utf-8",
},
});
}
1 change: 1 addition & 0 deletions packages/docs/content/api.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Defining schemas
description: "Complete API reference for all Zod schema types, methods, and validation features"
---

import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/basics.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Basic usage
description: "Basic usage guide covering schema definition, parsing data, error handling, and type inference"
---

import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/ecosystem.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Ecosystem
description: "Overview of the Zod ecosystem including integrations, tools, and community resources"
---

import {
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/error-customization.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Customizing errors
description: "Guide to customizing validation error messages and error handling patterns"
---

import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/error-formatting.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Formatting errors
description: "Utilities for formatting and displaying Zod errors"
---

import { Callout } from "fumadocs-ui/components/callout";
Expand Down
90 changes: 0 additions & 90 deletions packages/docs/content/generic-functions.mdx

This file was deleted.

3 changes: 2 additions & 1 deletion packages/docs/content/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "Intro"
mode: "center"
description: "Introduction to Zod - TypeScript-first schema validation library with static type inference"
---

import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
Expand Down Expand Up @@ -134,6 +135,7 @@ bun add zod@canary # bun
pnpm add zod@canary # pnpm
```

Zod provides an MCP server that can be used by agents to search Zod's docs. To add to your editor, follow [these instructions](https://share.inkeep.com/zod/mcp). Zod also provides an [llms.txt](https://zod.dev/llms.txt) file.

## Requirements

Expand All @@ -154,7 +156,6 @@ You must enable `strict` mode in your `tsconfig.json`. This is a best practice f
}
```

<br/>

## Ecosystem

Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/json-schema.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "JSON Schema"
description: "How to convert Zod schemas to JSON Schema"
---

import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/library-authors.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: For library authors
description: "Guidelines and best practices for library authors integrating with Zod"
---

import { Callout } from "fumadocs-ui/components/callout"
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/metadata.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Metadata and registries"
description: "Attaching and manipulatinvg metadata on Zod schemas"
---

import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
Expand Down
5 changes: 0 additions & 5 deletions packages/docs/content/object-vs-interface.mdx

This file was deleted.

1 change: 1 addition & 0 deletions packages/docs/content/packages/core.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Zod Core
description: "Zod Core package - minimal core functionality for custom implementations"
---

import { Callout } from "fumadocs-ui/components/callout"
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/packages/mini.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Zod Mini
description: "Zod Mini - a tree-shakable Zod"
---

import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
Expand Down
Loading