Legacy Code Documentation

Docstrings and a module README inferred from undocumented legacy code.

Intermediate · Works with ChatGPT, Claude, Gemini, Copilot

The prompt

Write docstrings for the functions and a short README for this module, based only on what the code actually does.

Mark anything you're inferring about intent rather than reading directly off the code, and note the part you're least sure about.

Code to document:
{{CODE}}

Language and any known context:
{{STACK}}

Why this prompt works

Separating inferred intent from observed behavior stops the docs from stating guesses as fact.

How to customize it

  • Verify at least the flagged uncertain parts against actual usage before trusting the README.
  • Add any tribal knowledge you have — it fills gaps the code alone can't answer.

Common mistakes

  • Treating inferred docs as authoritative without checking with someone who knows the history.
  • Documenting only the happy path and skipping the odd conditionals that hint at past bugs.

Example

Input

Code to document: billing/legacy_invoicer.py, no comments, last touched 4 years ago

What a good answer looks like

Per-function docstrings plus a short README with a flagged assumption or two.

Make this prompt fit your work

ModelCoach.ai scores your version, shows what to improve and explains why, right inside ChatGPT, Claude, Gemini and Copilot.

Related prompts