An AI is useful for explaining unfamiliar code, suggesting tests and reviewing a function. It is less useful when you ask it to write everything without context: the code it produces can look correct and not be.
Always give the language, the versions, the context and the expected result. Paste a minimal excerpt rather than the whole project.
State the exact error message and what you have already tried.
Review and test all generated code.
Never paste secrets: API keys, passwords, tokens.
Replace the parts in [brackets] with your own details, then paste the prompt into ChatGPT, Claude, Gemini, Copilot or Le Chat. To adapt a prompt, use the prompt generator.
1. Explain a piece of code
To understand a function you did not write.
You are a senior [language] developer. Explain the following code to a [beginner/intermediate] developer: [paste the code]
Format: one-sentence summary, line-by-line explanation of the important parts, approximate complexity, two risks or edge cases. If you lack the context to be sure about a point, say so instead of assuming.
2. Find the cause of a bug
When an error resists your first leads.
I have a bug in [language, framework, version]. Expected behavior: [description]. Observed behavior: [description].
Exact error message: [paste the error]. Relevant code: [minimal excerpt]. What I have already tried: [list].
Suggest the 3 most likely causes, ranked, and how to verify each one. Do not rewrite everything: first give the checks to run.
3. Write unit tests
To cover a function with useful cases.
Write unit tests with [test framework] for the following function: [paste the function]
Cover the normal case, edge cases (empty values, extremes, unexpected types) and errors. Give each test an explicit name. After the tests, list the behaviors the function does not handle and that I should decide whether to address.
4. Refactor without changing behavior
To clarify a long or confusing function.
Here is a [language] function that works but is hard to read: [paste the code]
Suggest a refactoring that keeps the behavior exactly the same: clearer names, splitting into small functions, removing duplication. Explain each change in one sentence. Tell me which tests to run to verify that nothing has changed.
5. Review a pull request
To get a second look before the human review.
You are a demanding code reviewer. Here is a [language] diff: [paste the diff]
Analyze it for: correctness, security (injection, input handling, secrets), performance, readability, missing tests. Sort the comments by severity: blocking, important, nit. Give the relevant line for each comment.
6. Write documentation
To document a module or an API.
Write the documentation for the following module for the developers on the team: [paste the code or description]
Outline: purpose, installation, minimal usage example, description of the main functions (parameters, return values, errors), known limitations. Markdown format. Do not invent any behavior: if information is missing, put a question mark to verify.
7. Optimize a SQL query
To understand why a query is slow.
Here is a SQL query for [engine and version]: [paste the query]
Table structure (columns and indexes): [description]. Volume: [order of magnitude]. Execution plan: [paste it if available].
Explain why it may be slow, suggest an optimized version and the indexes to consider, and tell me how to measure the gain before deploying.
8. Design a simple architecture
To compare options before coding.
I need to design [feature or service]. Constraints: [team, deadline, volume, required technologies].
Propose two architectures of different complexity, with pros, cons, risks and maintenance cost. Finish with a justified recommendation. First ask me the questions you need to avoid an overly generic answer.
9. Convert code from one language to another
To migrate a script while keeping its meaning.
Convert the following code from [source language] to [target language]: [paste the code]
Use the idiomatic conventions of the target language. List possible behavior differences (types, rounding, error handling, dates). Point out functions or libraries with no direct equivalent. Suggest 3 test cases to compare between the two versions.
10. Explain a security warning
To understand an audit or scanner alert.
A scanning tool flags the following in my [language, framework] project: [paste the alert, without secrets].
Explain in simple terms the risk and how an attacker could exploit it, and propose a fix with a code snippet. Tell me how to verify that the vulnerability is really fixed and whether other places in the code may be affected.
Review and test generated code
Code that compiles is not necessarily correct. The AI can invent a function that does not exist in your version of a library, forget an edge case or introduce a vulnerability. Review, run and test before merging, just as you would with a colleague's code.
Never paste secrets
Remove before sending: API keys, passwords, tokens, connection strings, certificates, internal addresses and customer data. Replace them with placeholder values. If a secret was pasted by mistake, consider it compromised and change it.
Proprietary code and licenses
Check your company's policy before sending proprietary code to an external service. For generated code, pay attention to the licenses of the libraries it suggests.
Limits
The AI does not see your whole project or your environment. Always state the versions, and prefer small, precise requests to a vague one. Check the official documentation when an API looks doubtful.
Frequently asked questions
Can I paste my company's code into ChatGPT?
It depends on your company's policy and the tool's terms. Many companies forbid sending proprietary code to a consumer service. Ask your security lead before any use.
How do I stop the AI from inventing functions?
State the library version, ask it to flag its uncertainties and check the official documentation. Always run the code: a nonexistent function usually causes an immediate error.
Can AI write an entire application?
It can produce a prototype, but maintenance, security and edge cases need your expertise. Work in small steps, test each part and keep an understanding of the whole.