Good prompts make coding assistants more useful, but a vague request can produce code that is difficult to verify or unsafe to merge. This reusable prompt pack gives you practical structures for explaining unfamiliar code, reproducing bugs, generating tests, refactoring, reviewing pull requests, documenting systems, and planning migrations. Adapt the placeholders to your language, framework, repository, and team standards, then keep the prompts close to the workflow where you use them.
Overview
AI coding prompts work best when they define the task, provide relevant context, set constraints, and specify the shape of the expected response. Asking an assistant to “fix this code” leaves important decisions unstated. A stronger request identifies the observed behaviour, the intended behaviour, the execution environment, and the evidence the assistant should use before proposing a change.
The prompts in this guide are deliberately tool-agnostic. They can be adapted for an IDE assistant, a chat-based coding tool, or an internal LLM application. Their value does not depend on a particular model or extension. The important practice is to give the assistant a bounded task and treat its output as a draft for review, not as automatically trusted code.
Before sending code or repository context, check your organisation’s rules for confidential information, credentials, customer data, proprietary algorithms, and security-sensitive configuration. Remove secrets and minimise the amount of code you share. When an assistant has repository access, restrict the task to the files and symbols it needs whenever the tool allows that.
Choose a prompt by task
| Task | Best starting prompt | Useful output |
|---|---|---|
| Unfamiliar code | Explain and trace | Responsibilities, data flow, risks, and questions |
| Bug investigation | Reproduce and diagnose | Hypotheses, evidence, reproduction steps, and a minimal fix |
| New behaviour | Plan before implementing | Assumptions, affected files, edge cases, and tests |
| Refactoring | Preserve behaviour | Small steps, compatibility concerns, and regression tests |
| Pull request review | Review against criteria | Prioritised findings with file, line, impact, and remedy |
| Migration | Inventory and sequence | Dependency map, staged plan, rollback points, and validation |
Template structure
A reusable coding prompt should be easy to scan and safe to modify. Use the following structure as a base:
- Role and objective: State what the assistant should help with and what a successful result means.
- Context: Include the relevant language, framework, runtime, repository conventions, error message, input, or changed files.
- Constraints: Specify compatibility requirements, performance boundaries, security rules, permitted files, and approaches to avoid.
- Process: Ask for analysis, assumptions, and a proposed plan before a large implementation.
- Output format: Request a diff, checklist, test cases, explanation, or clearly labelled sections.
- Verification: Ask how the result can be tested and what remains uncertain.
A compact master template looks like this:
Help me [objective] in [language/framework].
Context:
- Repository or module: [name]
- Relevant files or symbols: [paths and identifiers]
- Current behaviour: [what happens]
- Intended behaviour: [what should happen]
- Environment and versions: [details]
Constraints:
- Preserve: [API, behaviour, compatibility, performance]
- Do not change: [out-of-scope areas]
- Follow: [team conventions or security requirements]
First, state your assumptions and propose a small plan.
Then provide [diff / code / review / test plan].
Explain trade-offs, edge cases, and how I can verify the result.
If the context is insufficient, ask focused questions instead of guessing.
The final instruction is particularly useful. It gives the assistant permission to identify missing information rather than filling gaps with invented repository details. For a small, well-understood edit, you can omit the planning step. For a risky change, keep it and request an incremental implementation.
How to customize
Replace abstract context with evidence
Include the smallest useful example: the failing input, exact error text, relevant function, expected output, and a nearby test if one exists. “The API is slow” is less actionable than “the request takes several seconds when the result contains many records; the timing points to the serial loop in this function.” Avoid pasting an entire repository when a focused excerpt answers the question.
Define the boundary of the change
Tell the assistant whether it may alter public interfaces, database schemas, dependencies, generated files, or configuration. For example: “Keep the function signature unchanged and do not add a dependency. Prefer a change limited to the parser and its unit tests.” Clear boundaries reduce the chance of an apparently elegant but disruptive solution.
Ask for an appropriate response format
Use a numbered diagnosis for debugging, a unified diff for a targeted edit, a table for a review, and a checklist for a migration. If you need code, ask for complete functions or clearly marked patches rather than a mixture of fragments and unexplained prose. Request tests alongside implementation so that correctness is considered as part of the task.
Separate diagnosis from implementation
For non-trivial work, use two turns or two stages: first ask for hypotheses and a plan, then provide approval or corrections before requesting code. This makes it easier to catch a wrong assumption about data flow, permissions, or compatibility. It also creates a useful record for a code review or team discussion.
For more formal quality checks, pair these prompts with a prompt testing and regression process. The prompt testing and regression framework explains how to compare outputs consistently when prompts or models change.
Examples
1. Explain unfamiliar code
Explain this module for a developer joining the project.
Identify its public entry points, main data flow, side effects, error handling, and external dependencies. Trace one representative request from input to output. Do not infer behaviour that is not supported by the supplied code; label uncertainties and cite the relevant functions or files. Finish with three focused questions I should answer before changing it.
This is more useful than asking for a line-by-line paraphrase because it focuses on responsibilities and change risk.
2. Investigate and reproduce a bug
Investigate this bug without proposing a broad rewrite.
Observed behaviour: [symptom]
Expected behaviour: [expectation]
Reproduction steps: [steps]
Error or logs: [sanitised output]
Relevant code: [snippet or file paths]
Return:
1. The most likely causes, ranked by evidence.
2. A minimal reproduction or test that should fail before the fix.
3. The smallest safe fix, with assumptions clearly labelled.
4. Regression tests and checks for nearby edge cases.
If the evidence does not distinguish between hypotheses, say what additional logging or test would resolve that uncertainty.
3. Generate tests
Write tests for [function or component] using [test framework].
Cover the normal case, boundary values, invalid input, dependency failure, and any security-relevant path visible in the code. Follow the existing test style. Do not test private implementation details unless the current project convention requires it. For each test, state the behaviour it protects. Flag any case that cannot be tested without changing the production code.
4. Refactor without changing behaviour
Propose a behaviour-preserving refactor for [module].
Preserve the public API, output format, error semantics, and supported runtime versions. First identify duplicated logic and possible behavioural traps. Suggest changes in small, independently reviewable steps. For each step, provide the tests that should remain green and note any performance, readability, or compatibility trade-off. Do not combine the refactor with unrelated feature changes.
5. Review a pull request
Review the following change as a careful maintainer.
Focus on correctness, security, data validation, error handling, concurrency, performance regressions, backwards compatibility, and missing tests. Ignore formatting issues unless they affect maintainability or project conventions.
Return a table with: severity, file or symbol, finding, why it matters, and a concrete remediation. Separate confirmed issues from questions or suggestions. If no issue is found in a category, say so briefly. Do not invent execution results; distinguish static observations from checks that still need to run.
6. Plan a migration
Help plan a migration from [current technology or API] to [target].
Inventory affected modules, interfaces, data formats, dependencies, tests, deployment steps, and rollback needs using only the supplied repository context. Produce a staged plan with prerequisites, compatibility risks, validation criteria, and a definition of done for each stage. Highlight unknowns that require a spike or manual confirmation. Do not assume the target supports every current behaviour.
For model, API, or framework changes, compare this prompt with the relevant LLM API migration checklist. The same discipline applies: inventory dependencies, define validation, and preserve a rollback path.
When to update
Keep this prompt pack as a maintained team asset rather than a one-time collection. Revisit it when your coding assistant, IDE integration, model configuration, language stack, repository structure, or secure-handling rules change. A prompt that assumes whole-repository context may need revision if the assistant’s context selection changes. A request for a particular output format may also need adjustment when your team adopts a new review or testing workflow.
Update prompts after a repeated failure pattern: invented APIs, incomplete patches, missing edge-case tests, excessive scope, or reviews that report low-value issues. Record a small before-and-after example and change one instruction at a time where possible. Keep successful examples with the prompt so new team members can see the intended level of detail.
Use this practical maintenance loop:
- Choose one recurring development task, such as bug diagnosis or pull-request review.
- Save the prompt, input context, assistant output, and human corrections using sanitised examples.
- Evaluate the result against concrete criteria: correctness, scope, test coverage, clarity, and security.
- Revise the prompt or context requirements, then run it against the saved examples.
- Publish the improved version with an owner, last-reviewed date, and notes about known limitations.
Do not measure a prompt only by how much code it produces. A concise diagnosis, a useful test plan, or a clear list of unknowns can be the best result. For broader prompt design choices, see the guides to choosing an AI model and prompting, RAG, and fine-tuning. Start with one template, test it on real work, and refine it when the task, tool, or team practice changes.