- Clear context, constraints and examples produce much better code than vague requests.
- Ask the AI to plan first, write tests and explain trade-offs.
- Iterate in small steps and always review the result.
The Short Answer
The quality of AI-written code depends heavily on the quality of your request. A vague prompt like 'make a login page' gets a generic result. A clear prompt that states the language, framework, goal, limits and expected behaviour gets code you can actually use. Good prompting is a skill, and it is mostly clear thinking written down.
A Simple Prompt Formula
| Part | Example |
|---|---|
| Role and context | I am building a small booking site with HTML, CSS and JavaScript |
| Goal | Add a form that collects name, phone and date |
| Constraints | No external libraries, works on phones, validates the phone number |
| Output | Show the full file and explain each change in plain English |
| Checks | Also list edge cases and write a few tests |
Habits That Improve Results
- Share the error message: paste the exact text and the code around it.
- Ask for a plan first: 'Explain your approach before writing code.'
- Work in small steps: one feature or fix per prompt.
- Give examples: show sample input and the output you expect.
- State versions: tell it which language or library version you use.
Prompts That Reduce Risk
- 'Point out any security risks in this code.'
- 'List what could break with unusual input.'
- 'Do not change files other than the ones I mention.'
- 'If you are unsure, say so instead of guessing.'
Then verify the result yourself using our guide to reviewing AI-written code.
What Not to Paste
Never include passwords, API keys, customer data or private company code in a prompt unless your organisation has approved the tool. See using AI assistants safely at work.
Keep Improving
Save prompts that work and reuse them as templates. If the AI keeps making the same mistake, restate the rule at the start of the next prompt. For the wider picture, read what vibe coding is and compare tools in our AI coding agents guide.
Action Checklist
- State language, framework and goal
- Add constraints and examples
- Ask for a plan before code
- Request edge cases and tests
- Work in small steps
- Never paste secrets or private data


