API Reference Generator
You get:
- Javadoc/Doxygen noise with no real examples
- parameter names without explanations
- missing edge cases and error responses
- docs that drift from actual behavior
- developers reading source code instead of docs
But good API docs follow a pattern:
- what the function does (one sentence)
- parameters with types and constraints
- return values and error conditions
- working code example
- see-also related functions
Without structure, docs are incomplete.
This prompt transforms code + comments into professional reference documentation.
Assume the role of a technical writer who specializes in API documentation. Your task is to generate complete reference documentation from code. Generate: 1. FUNCTION/METHOD SIGNATURE - Formatted with type hints 2. DESCRIPTION - One-sentence summary - What it does, not how 3. PARAMETERS TABLE - Name, type, required/optional, default, description - Constraints (e.g., "must be positive integer") 4. RETURNS - Type and description - Success vs error scenarios 5. ERRORS / EXCEPTIONS - What conditions trigger each error 6. EXAMPLE - Minimal working code snippet - Example output if relevant 7. SEE ALSO - Related functions or endpoints INPUTS: Code Signature: [PASTE FUNCTION/METHOD/ENDPOINT SIGNATURE] Existing Comments (if any): [PASTE DOCBLOCK OR COMMENTS] Language: [JAVASCRIPT / PYTHON / TYPESCRIPT / GO / RUST / OTHER] Audience: [BEGINNER / INTERMEDIATE / EXPERT] RULES: - If no comments exist, infer from parameter names and code structure - Never leave a parameter undocumented - Examples must be runnable (not pseudocode) - Flag breaking changes or deprecations prominently
- Include type hints in your code signature — the prompt uses them heavily.
- Specify audience level: beginners need more explanation, experts want edge cases.
- For REST APIs, paste the route + expected JSON shape instead of a function signature.
- Review generated examples — they should compile/run in the target language.
- Use output directly in READMEs, Sphinx, JSDoc, or MkDocs.
Code Signature:
def fetch_users(db_session: Session, limit: int = 50, include_inactive: bool = False) -> List[User]:
“””Retrieve users from database with pagination.”””
# implementation omitted
Existing Comments (if any):
“””Retrieve users from database with pagination.”””
Language:
PYTHON
Audience:
INTERMEDIATE
This framework improves outcomes by forcing:
- parameter documentation (no blind spots)
- error conditions (what actually breaks)
- working examples (not placeholders)
- audience awareness (right level of detail)
- related functions (discoverability)
Great API docs don’t list what code does — they help developers succeed on first use.
Build Better AI Systems
Subscribe for advanced prompt engineering, AI coding tools, debugging frameworks, and practical strategies for developers and engineers.
