Document a function or API
Professional structure: role, context, objective, details, steps, format, criteria and self-check. Designed for better results, not guaranteed ones: always review the answer.
Never use real personal data. If you need to, run it through the data cleaner.
## Role Act as a technical writer who writes documentation for developers. ## Context My code works, but nobody else knows how to use it. ## Objective Write clear documentation with runnable examples. ## Details (fill in what is in square brackets) - [code or specification] - [audience: internal team or external users] - [format: README, docstring, OpenAPI] ## Step-by-step instructions 1. Describe the purpose in one sentence. 2. Document parameters, types, defaults and response. 3. Add two usage examples, one basic and one advanced. 4. List possible errors and how to resolve them. ## Output format Documentation in the stated format, ready to paste. ## Quality criteria - The examples match the real signature. - It does not document functions that do not exist. - It can be understood without reading the code. ## Self-check Before answering, check every quality criterion. If information is missing, ask me instead of making it up, and at the end state what you have assumed.
Objective
Write clear documentation with runnable examples.
When to use it
This prompt is brilliant when you have a messy, undocumented codebase and need to produce professional-grade documentation quickly without manually typing every parameter. It works best for standardising internal APIs or creating clear README files for open-source projects. However, it is not a replacement for code reviews. If your logic is inherently flawed or your naming conventions are nonsensical, the AI cannot fix the underlying structural issues. It is a tool for translation from code to human-readable text, not a refactoring engine.
Worked example: input (fictional data)
Worked example: full response
Variants
Quick Reference Summary
Instead of a full technical breakdown, produce only a concise summary and a single, one-line code example for each function. Focus on brevity and speed. This is perfect for generating a quick reference cheat sheet for your team to stick on their monitors or keep in a Slack channel for instant clarity.
Novice Developer Focus
Write the documentation specifically for a developer who is new to the project or junior in experience. Use plain, jargon-free language to explain complex logic. Include extra context on why certain decisions were made in the code, ensuring the reader understands the reasoning behind the implementation, not just what the parameters do.
API Specification Style
Focus strictly on the OpenAPI (Swagger) format. Organise the output to include request schemas, response objects, and HTTP status codes rather than descriptive prose. Ensure the structure is ready to be copied directly into a YAML configuration file to define a RESTful endpoint, focusing on strict data types.
Common mistakes
- Publishing documentation without testing the examples.
- Documenting internal details that will soon change.
- Ignoring the specific error handling conventions of the existing codebase. How to avoid it: Explicitly define your project's preferred error format in the prompt to ensure the AI output remains consistent.
- Failing to specify the target audience's technical proficiency level. How to avoid it: Always include a note about who will read the documentation so the tone and detail level match their needs.
- Over-explaining obvious code logic that is self-documenting. How to avoid it: Instruct the AI to focus on 'why' the code exists rather than simply describing what each variable line does.
- Using placeholders that don't match your actual variable naming style. How to avoid it: Provide a small snippet of existing documentation or a style guide so the AI mimics your established documentation patterns.
Related guide
General and assistant-specific tips
Tips by assistant
- Claude: ask for the result as an artifact to view and edit it separately from the chat.
Getting the most out of it
- Paste the prompt as is and only replace what is in [brackets].
- If the answer does not fit, do not start over: ask for “shorter”, “more formal” or “as a table”.
- Always review the result before using it: AI can get facts, dates or names wrong.
Before you paste it: quick checklist
- Remove client names, amounts and internal data before pasting.
- Say who the text is for and which tone you want.
- Ask for a specific length: “120 words max” or “three bullet points”.
- Read the result aloud and fix anything you wouldn’t say yourself.
How to adapt it to your assistant
The template works the same in ChatGPT, Gemini, Copilot or Claude because it only uses plain language. If your assistant supports fixed instructions (custom instructions, Gems or projects), you can store your preferred tone and format there and paste only the variable part. On a free plan, split long requests into two or three shorter messages.