Building with AI
How to write AI coding prompts: a template for beginners
A beginner's guide to prompting AI coding tools — goal, context, constraints and checks — with a fill-in template and before-and-after examples.
By the GenKid team · · Updated · Facts checked · 5 min read
Key takeaways
- A good coding prompt gives four things: the goal (what it should do), the context (what already exists and who it's for), the constraints (the limits) and the checks (how you'll know it works).
- Ask for one feature at a time; huge "build everything" prompts produce code that's hard to check.
- Include constraints the AI can't guess, such as "no external libraries" or "works on a phone screen".
- Ask the AI to explain its change in plain English, then read the code yourself.
- Prompting is a skill you can practise and improve, like writing.
Why your prompt matters
A good coding prompt is a mini specification with four parts: goal, context, constraints and checks. The clearer each part is, the closer the first result gets to what you had in mind.
Building apps by describing them to AI, often called vibe coding, depends on the prompt. AI coding tools are very good at turning clear instructions into code, and quite good at guessing when instructions are vague. The trouble is that their guesses may not match what you had in mind. A prompt like "make a game" leaves almost every decision to the AI. A prompt that describes the game, the rules and what "done" looks like gets you much closer to your idea first time.
Whether you're typing into a chatbot or giving a task to an AI coding agent that edits your files, the same rules apply. Educators have started treating this as a real skill. Researchers have even designed "prompt problems", where students are shown what a program should do and must write a prompt that makes the AI produce it — a way to practise describing problems precisely.
The four parts of a good coding prompt
Think goal, context, constraints, checks.
- Goal — what should the app or feature do? Be specific about behaviour, not just the topic.
- Context — what already exists? Which files, which part of the app, who it's for.
- Constraints — the limits: languages, no outside libraries, must fit a phone screen, keep it simple.
- Checks — how will you know it works? Describe a test you'll try.
A template you can copy
Goal: Add a [feature] that [does what] when [something happens].
Context: This is a [kind of app] for [who]. The code is in [files].
Constraints: Use plain HTML, CSS and JavaScript. Don't change [other parts].
Checks: When I [do something], I should see [result]. If I [odd input], it should [result].
Please explain your change in 3 short bullet points.Before and after
Before: "Make a quiz."
After: "Add a quiz with five multiple-choice questions about planets. Show one question at a time with four answer buttons. Keep a score at the top. After the last question, show the final score and a 'Play again' button that resets everything. Use plain HTML, CSS and JavaScript, no outside libraries. When I answer all five correctly, the score should say 5/5. Explain your changes in three bullet points."
The second prompt takes thirty seconds longer to write and saves several rounds of fixes.
One feature at a time
It's tempting to describe the whole app in one giant prompt. Resist. In one study of 33 learners aged 10–17, those who asked the AI for a complete solution in one go had the lowest scores when they later had to modify code themselves. The Raspberry Pi Foundation's summary of this research notes that learners who mixed AI-generated parts with code they wrote themselves showed more promising trends, although the differences were not statistically significant.
Small prompts also make the AI's changes easier to read and check. If something breaks, you know exactly which change caused it. Our guide to decomposition shows how to split an idea into features.
After the AI answers
The prompt is only half the job. After every change:
- Read the explanation, then find the code it describes.
- Predict what will happen before you run it.
- Test it, including odd inputs like an empty answer.
- Accept or reject the change. If it's wrong, say what's wrong specifically: "The score doesn't reset when I click Play again."
We cover this properly in how to review AI-generated code.
Common prompting mistakes
| Mistake | Better |
|---|---|
| "Make it better" | "Make the buttons bigger and give them more space on small screens" |
| "Fix it" | "When I click Next on the last question, the page goes blank. It should show the score." |
| "Add everything from my list" | One feature per prompt, tested before the next |
| Pasting personal details for "realism" | Use made-up names, places and data |
| Accepting code you don't understand | Ask "explain line 12 in simple words" |
That last-but-one point matters for safety: never paste real names, addresses, passwords or keys into a prompt. See what not to tell an AI and why you never paste an API key into code.
Prompting is a transferable skill
Writing a clear prompt is really just clear thinking: knowing what you want, explaining it precisely and defining success. Those skills help with essays, projects and teamwork, not just code. Professional developers do the same thing when they write specifications and tickets. When you're using AI to learn rather than to build, the prompts change: see hints, not answers. Want something to practise on? Pick a project from 25 app ideas kids can build with AI and write a prompt for its first feature, or follow a whole build from first prompt to finished app in how to vibe code.
Practise it in GenKid
GenKid's Build with AI lessons teach prompts as specifications — goal, context, constraints — with a coding agent that builds each change in a safe sandbox and shows exactly what changed. See the pathway or start free.
Frequently asked questions
How long should a coding prompt be?
Long enough to cover the goal, context, constraints and a check — often three to six sentences. Longer isn't better if it bundles several features together.
Should I tell the AI which programming language to use?
Yes, if it matters. For beginners, asking for plain HTML, CSS and JavaScript keeps code simple and readable in any browser.
What do I do when the AI keeps getting it wrong?
Describe exactly what's happening and what should happen instead, undo the bad change, and ask for a smaller step. Sometimes it's faster to make a small fix by hand.
Should I give the AI my whole app's code?
Usually not in one go. Coding agents that work inside your project can open the files they need, so tell them which part to look at. With a chatbot, paste only the part that matters plus a short description of the rest. Either way, check there are no passwords, keys or personal details in anything you share.
Sources
- Prompt problems: a new programming exercise for the generative AI era (opens in a new tab) — Denny et al., SIGCSE 2024
- How novices use LLM-based code generators to solve CS1 coding tasks in a self-paced learning environment (opens in a new tab) — Kazemitabaar et al., Koli Calling 2023
- Using an AI code generator with school-age beginner programmers (opens in a new tab) — Raspberry Pi Foundation, 2024
How we write: GenKid articles are researched and drafted with the help of AI tools, then checked in a separate review step against the sources listed above before they are published, and re-checked when they are updated. Rules and products change, so check official pages for your country before acting on anything here. This article is general information, not legal advice. Spotted a mistake? Email hello@genkid.app.