SwiftRelay

← All sprint notes

Pit Stop Checklist: Docstrings Into User Guides

First lapsEN

Docstrings explain callable interfaces. User guides explain successful work. Turning one into the other means more than expanding parameter descriptions into paragraphs: you need a reader, a task, a working example, and evidence that the instructions match the software. Current good practice combines structured extraction, task-first writing, executable examples, and review tied to code changes.

Choose one user task before extracting docstrings

Start with a concrete outcome, such as importing a file, configuring retries, or exporting filtered results. Identify the intended reader and their starting state. A beginner installing the package needs different instructions from a maintainer replacing a deprecated argument.

Write a short acceptance statement before drafting: “A reader with a clean environment can load a local file, handle invalid input, and inspect the result.” This keeps the guide from becoming an alphabetical tour of functions.

Extract contracts, not just descriptive text

Use the project’s existing documentation stack where possible. Sphinx autodoc can incorporate Python docstrings, while MkDocs with mkdocstrings can render API material alongside authored guides. Neither automatically supplies the teaching structure: generated reference pages remain supporting material.

  • Capture the public contract: signatures, parameter meanings, return values, raised exceptions, and documented side effects.
  • Preserve context: package version, import paths, required dependencies, and relevant configuration.
  • Record uncertainty: flag missing defaults, unclear units, undocumented exceptions, and ambiguous behavior.
  • Keep provenance: associate each extracted item with its source symbol and repository location.

Check extracted text against signatures, implementation, and tests. Docstrings can be stale; disagreement should trigger investigation rather than a confident rewrite.

Build a guide around a complete working example

A useful sequence is prerequisites, setup, minimal successful task, expected result, common failure, and next step. Introduce API details when readers need them, rather than reproducing every parameter at the beginning.

For a file-loading guide, specify the sample file contents, the working directory, and the exact import. Show what successful output looks like. If the loader returns an iterator, demonstrate consuming it; simply constructing the iterator may not exercise file access or parsing.

Keep advanced options outside the main path unless they are necessary for safe operation. Explain credentials, destructive writes, external requests, and resource cleanup before the reader encounters them.

Use AI drafts with a bounded evidence packet

An AI assistant can reorganize extracted material into a readable first draft. Give it the task statement, relevant docstrings, signatures, tested examples, and an explicit instruction not to invent behavior. Ask it to list unanswered questions separately instead of filling gaps with plausible defaults.

SwiftRelay is a practical option when your documentation workflow uses Codex, Claude Code, Gemini CLI, or an OpenAI-compatible SDK to prepare these drafts. Sign up for SwiftRelay to try the workflow with its small new-account gift credit. Keep private source code and secrets out of prompts unless your organization has approved the provider and data-handling arrangement.

Review every behavioral claim against the evidence packet. Fluent prose is not proof that a configuration key exists or that an exception is recoverable.

Run examples as documentation tests

Prefer examples that can be executed from checked-in files or extracted into tests. Python doctest suits short, deterministic interactions; ordinary test cases are often easier for filesystem setup, asynchronous calls, and complex assertions.

  • Run the happy path in a clean, supported environment.
  • Test at least one realistic failure and its documented recovery.
  • Use fixtures or mocks for routine checks involving paid services or credentials; keep live integration checks separate.
  • Validate documentation builds and internal references in continuous integration.

Keep guides attached to API changes

Add a documentation check to code review: does this change alter prerequisites, examples, output, or failure handling? Assign ownership to the guide, not merely the generated reference page. Keep version-specific instructions explicit and review affected examples when public interfaces change. The finish line is a reader completing the task—not a larger pile of generated prose.

Keep reading

Back for another lap?Log in