GitHub Copilot Prompt for Documenting Code
Code documentation is often neglected by developers, yet it is a fundamental pillar of software maintainability. GitHub Copilot, integrated directly into your code editor, turns this time-consuming task into a smooth and nearly instant process. By analyzing your code context — function names, parameters, return types, internal logic — Copilot generates relevant comments, docstrings, and technical documentation in seconds. Whether you are working on a REST API, an open-source library, or a corporate project, a well-crafted prompt enables Copilot to produce structured, consistent documentation that adheres to your language's conventions (JSDoc, Python docstrings, Javadoc, etc.). The challenge is not simply to describe what the code does, but to capture the why — architectural decisions, edge cases, business constraints. With the right prompts, Copilot becomes a true technical co-writer capable of significantly accelerating your documentation workflow without sacrificing quality.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Document this function by adding a complete documentation block in the standard format of the language used. Include: a concise description of the function's purpose, each parameter with its type and role, the return value with its type, possible exceptions or errors, a concrete usage example, and any notes on edge cases or side effects. Adopt a professional and technical tone. If the function is part of a public API, specify usage constraints and the version since which it is available.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
This prompt is effective because it provides a clear structure that Copilot can follow point by point, eliminating any ambiguity about the expected content. By mentioning the standard format of the language, it automatically adapts to the context (JSDoc, docstring, Javadoc). Including advanced elements like edge cases and side effects pushes Copilot beyond superficial documentation toward truly useful documentation.
Use Cases
Variants
Expected Output
Copilot generates a complete documentation block formatted according to the language's conventions, with a clear description, typed and documented parameters, return value, possible exceptions, and a usage example. The produced documentation is ready to be integrated directly into the source code and compatible with documentation generators like Sphinx, TypeDoc, or Javadoc.
Frequently Asked Questions
Can GitHub Copilot document code in any programming language?
Yes, GitHub Copilot supports documentation in the vast majority of common programming languages. It automatically generates the appropriate format based on the detected language: JSDoc for JavaScript/TypeScript, docstrings for Python, Javadoc for Java, XML comments for C#, rustdoc for Rust, and so on. Quality is especially high for the languages most represented in its training data (Python, JavaScript, TypeScript, Java, Go). For less common languages, it's recommended to explicitly specify the desired documentation format in your prompt.
How can I ensure that the documentation generated by Copilot is accurate and free of hallucinations?
Documentation generated by Copilot should always be reviewed and validated by the developer. Three best practices reduce the risk of inaccuracy: first, provide as much context as possible by keeping related files open in your editor. Second, use descriptive variable and function names—Copilot relies heavily on these semantic cues. Third, always check type descriptions, return values, and generated examples by comparing them against the actual code. Hallucinations are more common in behavioral descriptions than in structural elements like parameter types.
Is it better to use Copilot Chat or inline suggestions to document code?
Both approaches are complementary. Inline suggestions (by typing /** or """ above a function) are ideal for function-by-function documentation within a continuous development flow—it's fast and contextual. Copilot Chat is preferable when you need to document an entire file, generate a README, create architectural documentation, or finely customize the style and level of detail via a well-crafted prompt. For substantial projects, combine the two: use Chat to define documentation conventions, then inline to apply them throughout the code.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
💡 Précisez le langage et la convention attendue (JSDoc, docstring, XML…) dans votre prompt, sinon Copilot choisit un format par défaut. Placez le curseur dans la fonction et lancez la commande : le modèle exploitera le contexte exact du code. Si le style doit suivre votre projet, ajoutez un exemple existant en commentaire.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Sora Prompt for Creating E2E Tests
End-to-end (E2E) tests are essential for ensuring application reliability, but writing them remains time-consuming and repetitive. Sora, thanks to its advanced generation capabilities, makes it possible to automate the creation of complete E2E test scenarios in seconds. By formulating a precise prompt describing user journeys, expected interactions, and validation criteria, you obtain structured test suites covering nominal cases as well as edge cases. The prompt engineering approach applied to Sora transforms how QA and development teams approach test coverage. Instead of starting from a blank page, you describe the expected behavior of your application in natural language, and Sora generates the corresponding test code with appropriate assertions. This method significantly reduces the time needed to set up an E2E suite while maintaining a professional quality level. Whether you use Playwright, Cypress, or Selenium, the prompts presented here adapt to your technical stack and the complexity of your application.
Implement rate limiting
Protect APIs from abuse
GitHub Copilot Prompt for Creating a REST API
GitHub Copilot has become an essential assistant for developers looking to accelerate the creation of REST APIs. Thanks to its direct integration into the code editor, it understands the context of your project and generates structured code in real time. Whether you work with Node.js and Express, Python and FastAPI, or Java and Spring Boot, Copilot adapts to your tech stack to produce endpoints conforming to REST conventions. The main challenge lies in formulating the prompt: a well-structured prompt yields a complete API with data validation, error handling, authentication, and documentation. A vague prompt, on the other hand, will produce generic code requiring many adjustments. In this guide, we offer an optimized prompt that fully leverages GitHub Copilot's capabilities to generate a professional, testable, production-ready REST API. You will also discover variants adapted to your experience level as well as practical tips to get the most out of this tool on a daily basis.
Implement CSP with nonces
Prevent XSS with strict CSP