Build documentation for AI assistants #

View this page as Markdown

On this page

Prompt:

Make our docs readable by AI assistants, and keep the generated reference out of the whole text.

Also works: "Stamp the docs with the version they describe." "Our docs are served under /docs, not at the root."

If the site is served under a path such as /docs, pass that path as --base; without it, routes start at / (step 1). To leave a generated section out of the whole text, pass its slug as --full-text-exclude (step 2), and to stamp the version, pass --corpus-version (step 3). To keep text meant for AI assistants alone out of the HTML pages, wrap it in markdown-only markers (step 4). Then build, and read the machine files back after it (step 5).

What your AI does #

  • Passes the path the site is served under as --base, so that the routes in the machine files are addresses an AI assistant can open.
  • Finds the section generated from another source, such as a reference section, and passes its slug as --full-text-exclude. Those pages stay reachable but are left out of the whole text, which keeps it small enough for an AI assistant to read.
  • Passes the version of the product the corpus describes as --corpus-version, so that the manifest states it.
  • Wraps text meant for AI assistants alone, such as instructions for an AI assistant, in markdown-only markers, so that the HTML pages leave it out.
  • Builds, and reads back the index and the manifest to confirm the routes, the Optional listing, and the version.
  • Asks which version the corpus describes when the project does not state one.

What you need #

  • The web address path your docs will be served under, for example whether they sit at your site's root or under a subfolder.
  • Which version of your product these pages describe.

Before your AI starts #

Check the following before starting:

Steps #

1. Set the base path #

Pass the path the site is served under as --base. The build writes it in front of every route in the manifest, the index, and the whole text. It also goes in front of each page and file link in the Markdown copies and in each redirect stub's Markdown pointer. The pages link relatively, so the flag changes only those machine files, the pointers, and the 404 page's links. Given --origin, it also reaches the sitemap's addresses, each page's canonical link and og:url tag, and each redirect stub's canonical link. Without it, routes start at /.

tzdocs build --source docs --out site --base /docs

2. Keep the generated pages out of the whole text #

Pass the slug of the section to leave out as --full-text-exclude. Its pages are left out of the whole text and the index's section listing, and the index lists them under its Optional heading instead. They keep their HTML pages and individual Markdown copies, and the manifest marks each one in_full_text: false. This setting reduces the combined text; it does not hide a page or restrict access.

The prefix is tree-relative: /reference, not /docs/reference. It matches a page whose slug equals it or begins with it followed by /.

tzdocs build --source docs --out site --base /docs --full-text-exclude /reference

3. Stamp the version #

Pass the version of the product the corpus describes as --corpus-version. The build writes it as the manifest's top-level version, so that an AI assistant can read which version the pages describe before it opens one.

tzdocs build --source docs --out site --base /docs --full-text-exclude /reference --corpus-version 2.4.0

4. Keep text for AI assistants out of the HTML pages #

Where a page holds text meant for AI assistants alone, wrap it in the markers that Markdown-only sections gives. The page's index.md keeps the text, markers included. Its entry in llms-full.txt keeps it too, unless the build excludes that page from the full text. The HTML page leaves it out, and the manifest lists none of its headings. The text stays public wherever those files are served.

5. Read the machine files back #

Open llms.txt at the tree root. Confirm that the routes begin with the base path and that the excluded pages are listed under Optional. Open docs.json and confirm its version and each excluded page's in_full_text: false. Output describes the four kinds of machine file and the order in which an AI assistant reads them.

Beside llms.txt, a build given --origin also writes sitemap.xml, the list of every page's absolute address that search engines read. An AI assistant reads the index; a crawler reads the sitemap (Publish the site).

Expected result #

The success line gives the page count and the number of pages left out of the whole text. It has this form: built 40 pages into site; 12 pages excluded from the full text.

The index lists the excluded pages under Optional and every other page under its section, each route beginning with the base path. The manifest has the version, and the whole text contains every page except the excluded ones.

Refusals #

Refusals and findings gives the exact text.

Message Exit code Cause Remedy
--full-text-exclude needs a tree-relative slug prefix such as /reference, not "<value>" 2 The prefix is not a leading-slash path with safe segments. Write the section's slug, without the base path.
--corpus-version needs a non-blank value 2 The value is empty or whitespace. Write the version text, or leave the flag out.
the excluded prefix <value> matches no page 1 No page's slug equals the prefix or begins with it followed by /. Correct the prefix, or leave the flag out.
markdown-only section in <file> — nested opening marker; close the current section first 1 An opening marker appears before the preceding section closes. Close that section before opening another, or remove the nested pair.
markdown-only section in <file> — unmatched closing marker 1 A closing marker has no opening marker. Add the opening marker or remove the closing marker.
markdown-only section in <file> — unclosed opening marker; add <!-- /tzdoc:markdown-only --> 1 A section reaches the end of the page without closing. Add its closing marker on a separate top-level line.
  • Output describes the index, the manifest, the Markdown copy, and the whole text.
  • Getting started lists every flag with its default.
  • Glossary defines route, base path, and tree-relative.