LESSON 2

Writing Documentation With AI

Draft documentation with AI without inventing facts: ground drafts in sources, give the model a style guide and glossary, and verify every claim that can be checked.

Introduction

Ask a model to “write API documentation for SignalDesk” and you will get something that looks excellent: tidy headings, sensible endpoint names, helpful examples. Some of it will be true. The rest will be a confident description of the API the model would have designed.

This lesson establishes the working method used in the rest of the course: supply sources, constrain the output, verify the claims, and keep people responsible for what is published.

Learning Objectives

  • Recognize the characteristic failure modes of AI-written documentation.
  • Rank sources of truth and ground drafts in them.
  • Build a reusable context pack: style guide, glossary, and templates.
  • Write prompts that separate facts, assumptions, and unknowns.
  • Verify documentation claims, including by running them.
  • Decide what AI may draft and what a person must decide.

1. How AI-Written Documentation Goes Wrong

Failure Example Why it is dangerous
Invented detail A parameter, header, or error code that does not exist Readers write code against fiction
Plausible default “Rate limit: 100 requests per minute” when none is enforced Becomes an unintended promise
Restating the code “This function validates the row” Adds words, not understanding
Invented rationale “We chose a queue for scalability” when the reason was different Misleads future decisions
Stale knowledge Describing a library’s old version or a previous design Instructions that no longer work
Generic filler “This robust, scalable solution ensures seamless integration” Hides the lack of real content
Inconsistent terms “workspace”, “tenant”, “account”, and “organization” used interchangeably Confuses readers and search
Unsafe advice A command that deletes data, or a disabled security setting Real harm if followed
Leakage Real keys, hostnames, or customer data pasted into prompts or drafts Security and privacy incident

None of these are rare. They are the default behavior when a model is asked to produce documentation without grounding.

2. Sources of Truth

Rank what the model may rely on. When sources disagree, the higher one wins, and the disagreement is itself a finding.

Rank Source Trust for
1 Running system and executed examples What actually happens
2 Contract and schema (OpenAPI, database migrations, config definitions) Interfaces and data shapes
3 Code and tests Behavior, defaults, limits, error handling
4 Decision records, SRS, and design documents Intent and rationale (may be outdated)
5 People’s knowledge (interviews, review comments) Context, history, and unwritten rules
6 The model’s general knowledge Nothing about your system; only general concepts and wording

The model’s own knowledge is for language and structure, not for facts about your system. Every statement about SignalDesk should trace to ranks 1 to 5.

Rationale is special: it often exists only in people’s heads. If no source states why a decision was made, the draft should say “rationale not recorded” and ask the owner, not guess.

3. Build a Context Pack

A context pack is a small, versioned set of files you give the model every time. It makes drafts consistent and reduces repeated instructions.

1
2
3
4
5
6
7
docs/
  _meta/
    style-guide.md      Voice, terminology rules, formatting, reading level
    glossary.md         Approved terms, definitions, and terms to avoid
    audiences.md        Audiences, goals, and starting knowledge
    templates/          One template per document kind
    prompts/            Reviewed, reusable prompts

Style guide (keep it to one or two pages):

  • Address the reader as “you”; use the active voice and present tense.
  • One idea per sentence; prefer short words.
  • Start how-to titles with a verb (“Import feedback”); start reference titles with a noun.
  • Number steps; one action per step; state the expected result after the step.
  • Put warnings before the step they apply to.
  • Use code formatting for commands, paths, fields, and values; never for emphasis.
  • Say what the document does not cover.

Glossary: one approved term per concept, with a definition and the synonyms to avoid. For SignalDesk, decide once whether it is “workspace” or “tenant” in user-facing text (for example, “workspace” for users, “tenant” only in architecture documents) and enforce it.

Templates: a skeleton for each kind (tutorial, how-to, reference page, explanation, ADR, runbook), so drafts have the right shape from the start.

4. The Grounded Drafting Prompt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
You are drafting documentation for the audience described below.
Use ONLY the supplied sources for facts about the system.

Audience: [who, what they know, what they want to do]
Document kind: [tutorial | how-to | reference | explanation]
Goal of this document: [one sentence]

Context pack:
- Style guide: [paste]
- Glossary: [paste]
- Template: [paste]

Sources (ranked):
1. [executed output, contract, schema]
2. [code excerpts, tests]
3. [decision records, requirements, notes]

Rules:
- Every factual statement about the system must be supported by a
  source. After each section, list the sources used.
- If something needed is not in the sources, write [UNKNOWN: what is
  needed] instead of guessing.
- Do not state defaults, limits, versions, or guarantees unless a
  source states them.
- Use glossary terms exactly; do not introduce new names.
- Do not add marketing language.

Output: the draft, then a table of claims with source references,
then a list of [UNKNOWN] items and questions for the owner.

The [UNKNOWN] convention is the most valuable part. It turns silent invention into visible questions. Search for the marker before publishing; none may remain.

5. A Drafting Workflow

  1. Define the reader, the kind, and the goal in one sentence each.
  2. Gather sources (and run the thing, so that real output exists).
  3. Outline with the model, and adjust the outline yourself; structure is cheap to fix now.
  4. Draft section by section, not the whole document at once, with sources attached.
  5. Verify every checkable claim (next section).
  6. Edit as a human: cut filler, fix voice, add what only you know, answer the [UNKNOWN] items.
  7. Review by a second person who did not write it, ideally a member of the target audience.
  8. Merge through the normal pull request process (lesson 3).

Keep humans in steps 1, 6, 7, and 8. The model can assist all steps, but a person decides what the document is for and signs off on it.

6. Verifying Claims

Documentation contains claims of different types, and each has a verification method.

Claim type Example How to verify
Command make test runs the suite Run it on a clean machine
Code example A request that creates an import Execute it against a running instance
Interface fact “The status field is one of…” Compare with schema or contract
Default or limit “Maximum file size is 10 MB” Find it in code or configuration; test it
Behavior “Duplicate rows are skipped” Find the test; run the scenario
Rationale “We use a queue because…” Ask the decision owner; check the ADR
Promise “Imports complete within a minute” Confirm with the accountable person; usually remove it

A helpful discipline is to extract claims explicitly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Act as a fact-checker for technical documentation.

Inputs:
- The draft: [paste]
- The sources: [paste code, contract, tests]

Tasks:
1. Extract every factual claim about the system as a numbered list.
2. For each, mark: Supported (cite the source), Contradicted (cite
   it), or Unsupported (no evidence in the inputs).
3. List commands and code examples, and state what would have to
   be run to verify each one.
4. Flag promises, guarantees, and security statements for human
   decision.

Do not assume a claim is true because it is plausible.

Treat the output as a worklist, not a verdict. The model can miss claims or misjudge support. Run the commands and examples yourself; that remains the strongest check, and lesson 3 turns it into automation.

7. What a Person Must Decide

Some content must never be accepted from a model without an accountable human decision:

  • Rationale for decisions that were not recorded.
  • Guarantees and limits: performance, availability, rate limits, retention, supported versions.
  • Security and privacy statements: who can access what, how data is protected, what is logged.
  • Destructive or risky instructions: deleting data, rotating keys, disabling checks.
  • Legal and compliance wording.
  • Known issues and workarounds, which need confirmation from whoever triaged them.

When AI drafts such content, mark it for review and name the reviewer.

8. Protect Data and Attribution

  • Use synthetic data, placeholder hostnames, and fake keys in prompts and examples (example.com, sk_test_xxx).
  • Remove secrets from logs and configuration excerpts before pasting.
  • Use only tools your organization has approved for the sensitivity of the material.
  • Follow your organization’s policy on disclosing AI assistance and on licensing of generated text and code.
  • Review generated code samples as you would any code: they may contain insecure patterns.

9. Using AI as a Reviewer and Naive Reader

AI is often more valuable reviewing documentation than writing it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Act as a new reader with the stated background. Follow this
document literally, step by step.

Reader background: [e.g., backend developer, new to SignalDesk]
Document: [paste]

Tasks:
1. At each step, state what you would do and what you expect to see.
2. Stop and report whenever the instructions are ambiguous, assume
   knowledge you do not have, skip a step, or use an undefined term.
3. List terms that are not defined and not in the glossary.
4. List inconsistencies with the style guide.
5. Summarize the three biggest obstacles for this reader.

Do not fill gaps with your own knowledge. If a step cannot be
followed as written, say so.

This finds missing prerequisites and unexplained jargon quickly. It does not find factual errors about your system; verification does.

10. Practical Exercise

For SignalDesk (or your project):

  1. Create the context pack: style guide, glossary (at least 15 terms with terms to avoid), audiences file, and templates for the four kinds of documentation.
  2. Choose one small page, such as “Import feedback from a CSV file.” Gather real sources: the code, the CSV validation rules, and an actual run.
  3. Draft it twice: once with the prompt “write documentation for this feature,” and once with the grounded drafting prompt. Compare the two and list what the first invented.
  4. Run the claim extraction prompt on the grounded draft. Verify every command and example by running it.
  5. Resolve each [UNKNOWN] item with the owner or remove the claim.
  6. Run the naive reader prompt and fix what it reports.
  7. Save the reviewed prompts in docs/_meta/prompts/ for reuse.

Verification

You are ready to continue when:

  • The context pack exists and is stored with the project.
  • Every factual statement in your draft traces to a source, and no [UNKNOWN] markers remain.
  • Every command and example in the page was run, and you know the result.
  • Promises, limits, and security statements were approved by a named person.
  • You can describe at least three things the ungrounded draft got wrong or invented.

Key Takeaways

  • AI-written documentation fails by invention, filler, and inconsistency, not by awkward prose.
  • Rank sources of truth and let the model use its own knowledge only for language and structure.
  • A context pack of style guide, glossary, and templates makes drafts consistent.
  • Make unknowns visible with markers and questions instead of silent guesses.
  • Verify claims, above all by running them; people own rationale, guarantees, and safety.

What’s Next?

Verification by hand does not scale. Next, we treat documentation the way we treat code: stored in the repository, reviewed in pull requests, built and checked automatically on every change.