Writing Documentation

Prompt the model to write docs grounded in the real code: accurate docstrings, READMEs, and commit messages for a stated audience.

TL;DR

  1. Ground doc prompts in the real code so descriptions match behavior, not an invented version.
  2. State the audience and format: docstring, README section, commit message, or changelog entry.
  3. Review docs for accuracy; confidently wrong documentation is worse than none.

Ground It In Code

    Paste The Real Thing

    Document the actual function or diff, not a description of it.

    "Document this function exactly as
    written: <paste>"
    No Invented Behavior

    Forbid the model from adding behavior the code does not have.

    "Describe only what the code does.
    Do not infer extra features."
    Flag Unknowns

    Have it mark anything it cannot determine from the code.

    "If a side effect is unclear, note
    it as TODO, do not guess."

Docstrings

    Name The Style

    Specify the docstring convention so it fits your toolchain.

    "Use JSDoc with @param, @returns,
    @throws."
    Cover The Contract

    Purpose, parameters, return, errors, and one short example.

    what / params / returns /
    throws / example
    Skip The Obvious

    Do not restate types or trivially-named parameters.

    Explain the why and the gotchas,
    not "id: the id".

READMEs & Guides

    State The Audience

    Who reads it sets the depth, tone, and assumed knowledge.

    "For a new contributor on day one."
    Runnable Steps

    Ask for exact commands and prerequisites, not vague prose.

    "Give copy-paste setup commands,
    Node 20, pnpm."
    Structure It

    Request clear sections: setup, usage, config, troubleshooting.

    "Sections: Install, Run, Configure,
    Troubleshoot."

Commits & Changelogs

    From The Diff

    Generate the message from the actual staged changes.

    "Write a commit message for this
    diff: <paste>"
    Explain The Why

    The body should capture motivation the diff cannot show.

    "Subject + body. Body explains why,
    not just what."
    Match Convention

    Follow your format so history stays consistent.

    "Conventional Commits: type(scope):
    summary."

Tips

  1. Paste the actual function or diff and say 'document exactly what this does, do not infer extra behavior'.
  2. Give your docstring or commit convention as a template so output matches your project.

Warnings

  1. Models may document intended behavior rather than actual behavior; verify against the code.
  2. Auto-generated comments that restate the code add noise; ask for the why, not a line-by-line echo.

In Practice

FAQ