Prompting AI Coding Assistants
Prompting an AI coding assistant well means giving it a clear, specific request — the goal, the context, and the exact problem — so it can help on the first try instead of guessing. The difference is dramatic: “fix my code” makes the model guess your language and your bug, while “there’s a TypeError on line 15 because total is a string — convert it to a number” points it straight at the fix.
Learn Prompting AI Coding Assistants in our free AI & Machine Learning course — a beginner-friendly interactive lesson with worked examples, a practice…
Part of the free AI & Machine Learning course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
Tools like Claude and ChatGPT are incredibly capable, but they only know what you tell them. This lesson teaches the habits of a great prompt — the same precise, feedback-driven style that platforms like Codecademy use to keep learners unblocked.
What You'll Learn in This Lesson
1 Vague vs Specific — the single biggest lever
An AI assistant produces the most likely helpful answer to the words you give it. Vague words force it to guess; specific words let it solve. Same bug, two prompts:
The model has no code, no error, no goal. It will guess — and probably rewrite something you didn’t want.
Goal, language, the real error, the cause, and the desired output — nothing left to guess.
2 The anatomy of a great coding prompt
Strong coding prompts almost always contain these six ingredients. You don’t need all six every time, but the more ambiguous your problem, the more you should include:
Ingredient
Example
🎯 Goal
“Parse a CSV and return total revenue per month.”
🧰 Context
“Python 3.11, pandas 2.x, running in a Jupyter notebook.”
📄 The code
The smallest snippet that reproduces the issue.
❗ The error
The full traceback, pasted verbatim.
🚧 Constraints
“No new libraries; keep it under 20 lines; must handle empty files.”
📐 Output format
“Return only the corrected function, with a one-line explanation.”
Tip: asking for a specific output format (“just the diff”, “explain then code”, “add type hints and a test”) saves you re-prompting.
3 Report bugs precisely — paste the error, name the line
This is the highest-value habit in the whole lesson. Instead of describing a feeling (“it’s not working”), report the facts the way a good bug report does:
- What you expected — “I expected total to be 36.49.”
- What actually happened — the exact error or the wrong output.
- Where — the file and line number.
- Why you think it happens (if you have a guess) — “I think p is a string, not a number.”
Run this buggy snippet, read the real traceback, then practise turning it into a precise prompt:
4 Iterate with targeted follow-ups
The first answer is rarely the last. Treat it as a draft and steer with specific corrections — don’t throw it all away with “still broken”:
Other high-leverage moves: ask the AI to explain its reasoning , to list edge cases it didn’t handle, to write tests for the fix, or to give 2-3 approaches with trade-offs before you pick one.
📋 Copy-paste prompt template
Common Prompting Mistakes (and the fix)
- Describing the error instead of pasting it. — Paste the full traceback verbatim; the exact message and line number are gold.
- Dumping your whole repo. — Give the smallest snippet that reproduces the issue, not 800 lines that bury it.
- Saying “it’s broken” / “still wrong.” — State the new symptom precisely so the model can adjust, not restart.
- Hiding the goal. — The model fixes the symptom you describe; tell it what success looks like.
- Trusting blindly. — Read and test the answer. Ask it to explain anything you don’t understand before you ship it.
- No version/context. — “Python” vs “Python 3.12 + pandas 2.2” can be the difference between right and subtly wrong.
Frequently Asked Questions
⏱ Test Yourself — Timed Quiz
10 quick questions, 12 seconds each. Instant feedback — beat the clock!
🎉 Lesson Complete
- ✅ Specific prompts beat vague ones — give the model what you’d give a teammate
- ✅ A great prompt has a goal, context, the code, the error, constraints, and a format
- ✅ Report bugs precisely: paste the error and name the line (“syntax error on line 15”)
- ✅ Iterate with targeted follow-ups instead of “still broken”
- ✅ Always read, test, and understand the code before you ship it
Practice quiz
Your code crashes. What's the MOST useful thing to give the AI?
- A vague 'it's broken'
- Just the file name
- The full error message and the line number
- A screenshot with no text
Answer: The full error message and the line number. The exact exception, message, and line number often point straight at the cause.
Which is the better bug report to an AI assistant?
- 'TypeError on line 7: I'm adding a string to an int; convert with float() first'
- 'the total is wrong, help'
- 'fix my python'
- 'doesn't work'
Answer: 'TypeError on line 7: I'm adding a string to an int; convert with float() first'. Specific facts — what, where, and why — let the model solve instead of guess.
How much context should a coding prompt include?
- Your entire repo
- Nothing — let it guess
- Only the file name
- The smallest reproducible example plus language/version and the goal
Answer: The smallest reproducible example plus language/version and the goal. Enough to remove ambiguity, but the smallest snippet that reproduces the issue.
The AI's first answer fixed one bug but broke something else. You should…
- Start over with 'still broken'
- Reply with the new precise symptom (new error + line)
- Give up
- Paste the whole repo
Answer: Reply with the new precise symptom (new error + line). Iterate with targeted corrections; each specific symptom steers the model closer.
Why do specific prompts get better code?
- The model predicts the most helpful reply to YOUR words — specifics remove the guesswork
- The model charges more for vague ones
- Length is all that matters
- It doesn't matter
Answer: The model predicts the most helpful reply to YOUR words — specifics remove the guesswork. Vague input forces the model to guess your language, intent, and bug.
Which is NOT part of a great coding prompt?
- The goal
- The exact error
- Your astrological sign
- Constraints and desired output format
Answer: Your astrological sign. Goal, context, code, error, constraints, and output format are the six useful ingredients.
What should you do BEFORE shipping AI-written code?
- Nothing, just trust it
- Read and test it, and ask it to explain anything unclear
- Delete the tests
- Push straight to production
Answer: Read and test it, and ask it to explain anything unclear. Always read, test, and understand — the AI can be confidently wrong.
Best way to report a syntax error to an AI?
- 'syntax broken'
- '???'
- Say nothing and re-run
- 'There's a syntax error on line 15: a string is missing its closing quote — please close it'
Answer: 'There's a syntax error on line 15: a string is missing its closing quote — please close it'. Name the line and the precise cause — that's the highest-value habit in the lesson.
Pasting the FULL traceback vs describing it is…
- Worse — too long
- Better — the exact type, message, and line are gold
- The same
- Only for experts
Answer: Better — the exact type, message, and line are gold. Paste it verbatim; never paraphrase an error you could copy exactly.
Asking the AI for a specific OUTPUT FORMAT (e.g. 'just the diff')…
- Confuses it
- Is rude
- Saves you re-prompting and gets a tidier answer
- Has no effect
Answer: Saves you re-prompting and gets a tidier answer. Specifying the format ('explain then code', 'add a test') reduces back-and-forth.
Continue this course
- Previous: Building RAG Systems
- Next: Ethical AI & Bias