RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /How-to
  5. /How to use AI to convert legacy comments into idiomatic framework documentation
HOW-TO · DEV

How to use AI to convert legacy comments into idiomatic framework documentation

intermediate·20 min·By Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.x
PREREQUISITES

Legacy codebase with inline code comments, AI assistant access (OpenAI or Anthropic compatible), Node.js 18+ or Python 3.10+

What this does

Legacy codebases often contain inline comments written in prose style that describe behavior, intent, and caveats. This guide explains how to use an AI assistant to parse those comments and generate modern, idiomatic documentation in formats such as JSDoc, Sphinx RST, Markdown README sections, or OpenAPI descriptions. The process extracts meaning from unstructured text and repackages it into structured, machine-readable documentation that frameworks, IDEs, and CI tools can consume directly.

Steps

  1. Run a script or manual grep to collect all comment blocks from the target source files into a single text file, preserving the file path and line number for each block.
  2. Create a prompt for the AI assistant that includes the target documentation format (e.g., JSDoc), a representative sample of three to five comment blocks, and instructions to produce one structured entry per block.
  3. Send the collected comments to the AI assistant with the prompt. Request output in Markdown or JSON lines format, one entry per comment block.
  4. Review the generated entries. Check each one for accuracy against the original comment and for alignment with the project's chosen documentation style guide.
  5. Write a second AI prompt to split long or multi-topic comments into separate entries and deduplicate near-identical entries across files.
  6. Apply the generated entries back into the source files as inline documentation, or merge them into a central documentation file (e.g., docs/api.md).
  7. Delete or mark as migrated the original comment blocks that have been successfully converted.

Verification

# Verify new documentation blocks exist in the source tree
grep -r "@param\|@returns\|@throws" --include="*.py" --include="*.js" . | wc -l
# Expected: integer greater than 0; count reflects new structured doc entries

Common failures

  • Comment blocks are too terse or contain placeholder text. AI output will reflect poor input quality. Pre-process sparse comments by adding context before sending to the AI.
  • Generated JSDoc does not match project conventions. Run a linter (ESLint with JSDoc rules, or pydocstyle) on the output to surface mismatches early.
  • Original comments were not removed, creating duplication. Use a diff tool to compare the before and after state and explicitly delete migrated comment lines.
  • AI model pads output with explanations instead of clean doc blocks. Refine the prompt with a zero-shot instruction such as "Return Markdown code blocks only. No preamble."
  • Version mismatch - The installed package or runtime differs from the command shown; check the version first and rerun the smallest verification command.
  • Local environment drift - Another service, virtual environment, model, or path is being used; print the active binary path and configuration before changing the guide steps.

Related guides

  • Integrate an AI assistant into your API client library to auto-generate usage examples
  • Use AI to transform legacy API response schemas into modern typed structures
← All how-to guidesCourses →