Add Docstrings and Why-Focused Comments to Your Pasted Code
Returns your code with standard-style docstrings covering parameters, return values and raised errors, plus comments that explain intent rather than restate the code.
You getThe full documented code in one code block and changes
Prompt
Act as a senior software engineer who reviews code for readability.
I will paste code right after this message. Add docstrings and comments without changing what the code does.
Rules:
1. Detect the language and use its standard docstring style: Google style for Python, JSDoc for JavaScript/TypeScript, Javadoc for Java, XML doc comments for C#, GoDoc for Go. If the file already follows a style, match it.
2. Every public function, method and class gets a docstring with a one-line summary in the imperative mood. Follow it with each parameter's type and meaning, the return value, and every error the code raises or lets pass through.
3. Inline comments explain why: intent, edge cases, workarounds, non-obvious limits. Never write a comment that restates what a line plainly does.
4. Do not rename, reorder or refactor anything. If you spot a likely bug, flag it in a comment starting with NOTE: and leave the code as is.
5. If the purpose of a block is unclear, add a comment asking what it is for. Do not guess.
Output format:
1. The full documented code in one code block.
2. Changes: one bullet per function or class describing what you added.
3. Open questions: anything you could not infer from the code.
End with one line listing any assumptions you made about types or intended behavior.Example output
Tips and common edits
Why this works
- Naming the docstring style per language gives output that matches linters and IDE tooltips instead of a generic format.
- Requiring raised errors in every docstring makes the model trace failure paths, which often surfaces hidden bugs.
- Banning what-comments and refactors keeps the diff small and reviewable, with bugs flagged rather than silently changed.
Use before a code review or when handing code to a teammate. Paste one file or a few related functions into ChatGPT, Claude or Gemini. For large files, send one module at a time.
Common edits
- Switch Python to NumPy or reST docstring style to match your project's Sphinx setup.
- Allow light refactoring, such as renaming unclear variables, and ask for a separate list of those changes.
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
Keep exploring
More like this
Explain a Confusing Coding Tutorial or Docs Passage in Plain English
Paste a confusing passage from a programming tutorial or docs and get a plain-English rewrite, inline jargon definitions, a tiny runnable example and a list of what to learn first.
Review a Beginner's Code with Kind, Prioritized Feedback on the Top 3 Fixes
Paste your code and get a mentor-style review with one specific compliment, the three highest-impact fixes ranked with corrected snippets, and one next step.
Explain Pasted Code Line by Line with a Worked Example for Beginners
Get a block-by-block walkthrough of any code you paste, with one example input traced through every step and three questions to check that you understood it.
Refactor Pasted Code for Readability Without Changing Its Behavior
Returns a cleaner version of your code plus a change log that explains each edit, why behavior is preserved, and which edge cases you should test.
Write a README From Your Code and Notes Without Invented Commands
You get a complete README with requirements, install, usage and config sections built only from your pasted code, plus a list of gaps to fill.
Get Socratic Coding Hints in Three Levels Before Seeing the Full Solution
A patient tutor that gives escalating hints on your coding exercise, one level at a time, and shows full code only after you have tried twice.