ChatGPT Prompt for Code Documentation: 12 Docstring Prompts
12 ChatGPT prompts for code documentation: behavior inventories, docstrings, runnable doctest examples, README usage notes and TODO lists for unknown behavior.

A ChatGPT prompt for code documentation should describe what the code does, not what its author meant, and mark every unknown with a TODO. The 12 prompts below turn pasted code into docstrings, usage examples, README sections, change notes and a list of the behaviors nobody has tested, and each one asks you to check the result by running the examples and comparing it to the code. Paste only code you are allowed to share and keep secrets and customer data out.
To document a module end to end, with a behavior inventory, Google-style docstrings, runnable doctest examples and a TODO list, use the code documentation prompt for docstrings from pasted code.
Understand the code first
1. Behavior inventory
Here is a function [paste]. List its inputs, return value, side effects and every error it can raise, and cite the line that shows each one. Do not describe intent.
2. Unclear branches
Read this code [paste] and list every branch whose purpose you cannot tell from the code alone. Write each as a question for the original author.
3. Edge case reading
By reading this function [paste], say what happens with: empty input, None, negative numbers, very large values and repeated items. Mark each one "by reading" and do not claim it was tested.
Write the documentation
4. Docstrings
Write [style] docstrings for the functions below [paste]. Use only behavior visible in the code or in these test notes [notes]. Add TODO beside anything uncertain.
5. Doctest examples
Write three doctest examples for this function [paste] that you can work out by hand. Show the result on the next line so I can run them with python -m doctest.
6. Class docstring
Write a class docstring for [class] [paste]: purpose in one sentence, attributes set in the initializer and one line for each public method. Do not mention methods you cannot see.
7. README section
Write a README "Usage" section for this module [paste] with an install note only if I give one [install], one short example per public function and a list of exceptions callers should catch.
Keep it honest
8. Docstring versus code audit
Compare this docstring [paste] with this code [paste]. List every claim the code does not support and every behavior the docstring leaves out.
9. Missing tests list
From these docstring TODOs [paste], write a list of tests to add: the input, the expected behavior to decide and who should decide it.
10. Type hint proposal
Suggest type hints for these functions [paste] based only on how the values are used. Mark each one "inferred" and list the places where the code accepts more than the hint says.
Share it
11. Changelog entry
From this diff [paste], write a changelog entry that lists behavior changes only: what callers will notice, what they must update and anything that now raises an error. Skip refactors.
12. Onboarding note
Write a half-page onboarding note for a new developer on [module]: what it does, the three functions to read first and the known gaps from these TODOs [paste].
Worked example: two small utility functions
In the prompt's sample, a duration parser and a log batching generator are documented from the code and from three known tests. The inventory finds that the parser accepts negative values and raises ValueError for "1.5h" through int(), and that the batcher never validates size, so a size of 0 returns everything in one list. The docstrings state what the code does, include doctest examples worked out by hand, and put the negative-value and size questions in a TODO list instead of deciding for the author.
Tips
- Run every doctest; delete failing examples rather than changing the expected output.
- Treat each TODO as a ticket for the author or a test you need to write.
- Never paste secrets, tokens or customer data into a prompt.
- Keep docstrings short; the README and the tests carry the rest.
PromptDig is not affiliated with any programming language, documentation host or software vendor.
Related on PromptDig
Reviewing a written draft? See ChatGPT prompts for document review. Write tests next with ChatGPT prompts for test cases. For everyday code tasks read ChatGPT prompts for programming. More in the Coding hub, browse all prompts, or share your own documentation prompt.