keepcalculator

06 Numbers and Powers

Keep AI-Generated Documentation Accurate as Code Changes

Card No. 06·56741 · Updated · Standard formula, shown below

AI-generated documentation can save time, but it becomes unreliable when code changes without the related explanations being checked. Use a repeatable process that treats documentation as part of the codebase: identify what changed, update only what the evidence supports, and verify the result before merging.

What You’ll Need

  • Access to the repository, its current documentation, and the code or configuration being described.
  • A way to review changes, such as a pull request or code review, and to run relevant tests or documentation checks.
  • The project’s documentation conventions, including its intended audience, terminology, and source-of-truth files.
  • An approved AI tool, if your organization permits one. Follow its rules for source code, credentials, customer data, and other sensitive information.

Step-by-Step

  1. Decide what documentation must stay in sync. List the parts most likely to become stale: public APIs, command-line options, configuration keys, setup instructions, architecture decisions, examples, and troubleshooting steps. Record where each is maintained. A short ownership map is often enough; avoid creating a second inventory that itself needs constant updating.
  2. Set a clear source of truth. For behavior, prefer the implementation and executable tests over old prose. For intended public behavior, also check approved specifications or design decisions. Identify which file governs each fact. Do not let an AI tool resolve conflicts by guessing, and do not treat generated text as evidence that the code behaves a certain way.
  3. Make the code change first, then inspect its impact. Review the diff and ask what a user, operator, or maintainer would notice. A renamed option may affect a reference page, examples, and migration notes; an internal refactor may affect none. Search for the old name, changed defaults, affected routes or symbols, and links to relevant pages. Use repository search or a script where practical.
  4. Give the AI a bounded task and relevant context. Supply the changed files, the specific documentation files, audience, style rules, and a request to flag unknowns rather than invent details. Ask for a proposed patch or a list of claims to verify—not a broad rewrite of the whole documentation set. Exclude secrets and restricted data, and use only tools approved for the material.
  5. Check every factual claim against evidence. Compare names, defaults, units, supported versions, prerequisites, error behavior, and examples with code, tests, and configuration. Verify that commands and snippets still run where possible. If behavior is unclear, inspect the implementation or ask the responsible maintainer; remove or qualify claims that cannot be confirmed.
  6. Review the documentation diff like code. Check that the change is focused, readable, and consistent with project terminology. Confirm links, headings, code formatting, and any generated files. Make sure the prose describes observable behavior rather than implementation details that may change without affecting users. Avoid accepting polished wording as proof of correctness.
  7. Run documentation checks. Use the repository’s available build, link checker, spelling or style checks, and executable-example tests. Follow the project’s normal instructions, since commands vary. If a check cannot run locally, note that and use the appropriate continuous-integration result or ask someone with access to verify it.
  8. Include documentation in the change review. In the pull request, summarize what behavior changed and which pages were updated or confirmed unnecessary. Ask a reviewer familiar with the affected area to check both code and docs. Merge only after required checks pass and any unresolved documentation assumptions have an owner.
  9. Maintain the process after merging. Keep useful documentation checks in continuous integration and add regression tests for examples that are easy to break. When a recurring change repeatedly leaves a page stale, add a review checklist, ownership note, or test at that point in the workflow. Periodically remove obsolete pages rather than layering new caveats onto them.

Common Mistakes

  • Asking for a full documentation rewrite. Broad prompts can change correct material and introduce unsupported details. Limit the task to affected files and claims.
  • Trusting plausible output. A tool may fill gaps with familiar but incorrect defaults, flags, endpoints, or version details. Verify these against the repository or authoritative project material.
  • Updating prose but not examples. Commands, snippets, screenshots, and cross-links may be the most visible stale parts. Search for old names and test examples when feasible.
  • Documenting intent as current behavior. A proposal or comment does not guarantee that code implements it. Describe what the shipped behavior does, and distinguish planned work clearly.
  • Skipping review because the change is “only docs.” Incorrect setup steps or API guidance can waste users’ time. Documentation needs an appropriate factual review, even when no source code changed.
  • Sending sensitive material to an unapproved service. Follow organization rules for source, logs, personal information, and credentials. Remove sensitive data before sharing, or do the work locally with approved tools.

Tips

  • Put short, stable explanations near the code they describe, and keep user-facing guides in the documentation site. Link between them instead of copying the same details in several places.
  • Use tests for important examples, command output, schemas, and API behavior where the project can maintain them. Generated reference pages are most dependable when built from a maintained source such as code annotations or a schema.
  • Prefer precise wording: name the applicable version, state whether a value is a default, and distinguish required settings from optional ones.
  • Ask the tool to identify uncertainty and cite the files or tests supporting each proposed claim. Treat citations as pointers to inspect, not as automatic verification.
  • Keep the final prose understandable without knowledge of the AI process. Readers need accurate instructions, not a description of how text was drafted.

Troubleshooting

The AI describes behavior that is not in the code: Stop and compare the claim with implementation and tests. Remove it or ask the responsible maintainer to resolve the discrepancy; do not patch code merely to match generated prose without an approved requirement.

A documentation check fails: Read the failure output and identify whether it is a broken link, formatting issue, build dependency, or executable example. Fix the underlying problem, then rerun the relevant check. If the failure is unrelated, document why and use the project’s established process for reporting or deferring it.

You cannot tell which pages are affected: Search for changed symbols, option names, endpoints, and examples. Check navigation and links from the relevant page, then ask the component owner to confirm the likely user-facing surface. Record any remaining uncertainty in the review rather than claiming completeness.

Different sources disagree: Identify the designated source of truth and compare it with shipped behavior. If the disagreement is real, raise it for a product or maintainer decision; update the docs only after the intended behavior is clear.

Pages keep going stale: Find the change that breaks the process. Add a focused test, generated reference, ownership assignment, or pull-request checklist there. Avoid relying on a general reminder that does not identify which documentation is affected.

Frequently Asked Questions

Should AI write documentation directly from source code?
It can draft or update reference material, but a person should verify that descriptions match intended, user-visible behavior. Code alone may not explain why a feature exists or how users should apply it.

Can documentation updates be automated?
Yes. Generate stable reference content from maintained schemas or annotations, and test examples in automation. Keep conceptual guides and decisions under human review because automation may not capture context.

How do I know whether a code change needs a documentation update?
Check whether it changes something a reader relies on, such as a public name, default, workflow, requirement, output, or supported behavior. If not, note that existing docs were checked when the distinction may be unclear.

What if the AI gives no sources for its claims?
Ask it to point to repository files or tests, then inspect those sources yourself. If it cannot identify evidence, treat the claim as unverified and check it manually or leave it out.

Should every documentation example be tested?
Test examples that users are likely to copy and those that describe critical workflows. For examples that cannot be run automatically, provide a clear manual review and check them whenever related code changes.

How often should documentation be reviewed?
Review it whenever a related behavior changes, rather than waiting for a calendar-based audit. Periodic reviews can still help find abandoned pages and broken links, but they do not replace change-based checks.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →