Prompt Engineering for Web Developers: A Practical Guide
Write prompts that get working code from AI assistants: give context, state constraints, ask for small changes, show examples, and verify the output.
By UndieGravity, , 2 min read
An AI assistant only knows what you tell it plus what it can see in your project. Most bad answers come from missing context, not from a weak model. Prompt engineering for developers is mostly the habit of giving the right context and asking for the right size of change.
1. Say what you are working with
Name the stack and versions. "Next.js 16 App Router, TypeScript, Tailwind CSS v4" prevents answers written for an older version, such as getServerSideProps or a tailwind.config.js file.
2. Describe the goal, not just the task
Weak: Add a contact form.
Better: Add a contact form to app/contact/page.tsx. Fields: name, email,
message. Validate on submit and show errors under each field.
Post to /api/contact. Use the existing Input and Button components
in ui/. No new dependencies.The better prompt names the file, the fields, the behavior, the components to reuse, and a constraint. Each of those removes a guess.
3. State the constraints
- "Do not add new dependencies."
- "Keep the existing API; only change the internals."
- "Follow the pattern in features/blog/BlogCard.tsx."
- "Must work without JavaScript."
4. Ask for small steps
"Build the whole dashboard" produces a lot of code you cannot review. Ask for one piece at a time: the layout, then the table, then the filters. Small changes are easier to check and easier to undo.
5. Show an example
If you want output in a particular shape, paste one finished example. One good example often works better than a paragraph of description, especially for data formats, naming, and code style.
6. Paste the real error
When something fails, paste the full error message and the command that produced it. "It doesn't work" gives the assistant nothing to go on; a stack trace usually points straight at the line.
7. Ask it to explain or plan first
For anything non-trivial, ask for a short plan before code: "List the files you would change and why. Do not write code yet." You catch wrong assumptions before they turn into 200 lines.
8. Verify everything
- Run the code and the type checker.
- Check that imported packages actually exist and are spelled correctly.
- Read security-sensitive parts yourself: auth, payments, anything touching user data.
A template makes prompts better too: the assistant can follow the patterns already in the code instead of inventing its own. Start from a template and ask for changes in its style.