Use this guide whenever you ask an AI assistant to write or change code and keep getting answers that do not fit. Have a short description of your project, the language and framework you use and any relevant code or error messages ready.
Step by step
State the goal in one sentence
Start with what the code should do from the user's point of view, for example: add a form that saves a customer's name and email. Avoid vague requests like make it better. A clear goal stops the AI guessing.
Give the context
Say which language, framework and versions you use, and paste the relevant files or functions. Mention how the code is run, such as a web server or a script. Leave out unrelated code so the AI focuses on what matters.
List the constraints
Say what must not change, which libraries you can or cannot use and any rules such as no new dependencies or must work offline. Mention security needs, such as never storing passwords in plain text. Constraints prevent answers that work in isolation but break your project.
Specify the output format
Ask for exactly what you want back, such as the full updated file, only the changed function or a step-by-step list of changes. Ask for short comments explaining any tricky parts. This makes the answer easy to apply and review.
Ask for tests and edge cases
Ask the AI to include a simple test or example of how to check the code works. Ask it to list edge cases it handled, such as empty input or network errors. This gives you a way to verify the result.
Iterate with specific feedback
If the answer is wrong, paste the exact error message or describe exactly what happened versus what you expected. Change one thing at a time. Save prompts that worked well as templates for next time.
Ready-to-use checklist
- One-sentence goal
- Language, framework and versions stated
- Relevant code pasted
- Constraints listed
- Security needs mentioned
- Output format specified
- Test or check requested
- Error messages pasted in full when iterating
Practical tips
- Break big features into small prompts, as AI tools produce more reliable code for focused tasks.
- Never paste real passwords, API keys or customer data into a prompt; replace them with placeholders.
- Ask the AI to explain its code in plain English before you use it, so you understand what you are adding.
Common problems
The AI keeps using a library I do not have.
Add a constraint such as use only the standard library and the packages listed here, and paste your dependency file. Ask it to rewrite the answer within those limits.
The code works alone but breaks the rest of my app.
Give more context by pasting the files that call or are called by the changed code. Ask the AI to keep existing function names and behaviour unchanged.
The answers are long and hard to apply.
Ask for only the changed function or a clear list of changes with file names. Request one step at a time for larger changes.