What Is an AI Coding Assistant
An AI coding assistant is a helper inside your code editor. You tell it what you want in plain words. It writes or fixes the code. You check it and run it.
In short: it is an AI that lives in your editor, turns your words into code, and speeds up your work — but you stay in charge of reviewing and testing.
Why it matters
Writing code by hand is slow. An assistant does the boring parts fast: boilerplate, small functions, tests, fixing errors. You spend more time on the real problem. It is also a great teacher — it can explain code in simple words.
What the words mean
- AI coding assistant: a tool in your editor that writes code from your request.
- LLM (large language model): the "brain" that was trained on lots of code and text.
- Prompt: the request you type (a sentence, or a code comment).
- Context: the files and text the assistant can see when it answers.
- Suggestion: the code it offers; you accept or reject it.
How it works, top to bottom
The three modes
Almost every assistant works in three modes. You will switch between them all day.
- Inline (autocomplete): as you type, it shows faint "ghost" code. Press Tab to accept. Best for finishing a line or a small function.
- Chat: a side panel where you ask questions like "write a function that reads a CSV" or "why is this error happening?". Best for bigger blocks and learning.
- Agent: you give a goal; it edits several files and can run commands — asking your approval. Best for multi-step tasks. More power means more care.
Chat vs Inline vs Agent
How to prompt for code (simple rules)
- Say the goal + the inputs + the output. "Write a Python function that takes a list of numbers and returns the average."
- Name the language and tools. "Use pandas." "No external libraries."
- Give an example of input and expected output when you can.
- Ask for small pieces, then build up. Short requests give better code.
Always review and test AI code
- Read it line by line. If you do not understand a line, ask the assistant to explain it.
- Run it on a small example and check the result.
- Write a test (you can ask the AI for one) and run it.
- Watch for made-up things — AI can invent function names or libraries that do not exist. Check the docs.
Safety basics
- Never paste secrets (passwords, API keys, real customer data) into a cloud assistant.
- Check licences if it produces a large chunk that looks copied.
- For private data, use a local model (Ollama) so nothing leaves your machine — see Keep data at yourself.
Practice: your first explain, fix and verify loop with any AI coding assistant
Hello friends. The chapter above explained what an AI coding assistant is and why you must review and test its code. Now you will practise the full loop once. The practice is a fictional stall called Mango Grove Juice Corner, which sells three sizes of mango juice. First you ask the assistant to explain the code without changing it, then you ask it to fix the bug, and then you read the change and run the tests yourself. The starter file fails 4 tests and passes 3, and a correct fix passes all 7.
नमस्कार मित्रांनो. वरच्या chapter मध्ये आपण AI coding assistant म्हणजे काय आणि त्याचा code review आणि test का करायचा ते समजून घेतलं. आता हे पूर्ण चक्र एकदा करून पाहूया. हा सराव Mango Grove Juice Corner नावाच्या काल्पनिक stall वर आहे, जिथे mango juice तीन sizes मध्ये मिळतो. आधी assistant ला code न बदलता समजावून सांगायला सांगा, मग bug fix करायला सांगा, आणि मग बदल वाचून tests स्वतः चालवा. Starter file मध्ये 4 tests fail आणि 3 pass होतात, आणि बरोबर fix केल्यावर सगळे 7 pass होतात.
नमस्ते दोस्तों. ऊपर के chapter में हमने समझा कि AI coding assistant क्या है और उसके code को review और test क्यों करना ज़रूरी है. अब यह पूरा चक्र एक बार करके देखते हैं. यह अभ्यास Mango Grove Juice Corner नाम के काल्पनिक stall पर है, जहाँ mango juice तीन sizes में मिलता है. पहले assistant से code बिना बदले समझवाओ, फिर bug ठीक करवाओ, और फिर बदलाव पढ़कर tests खुद चलाओ. Starter file में 4 tests fail और 3 pass होते हैं, और सही fix के बाद सभी 7 pass होते हैं।
Ravindra Bagale's Tip
Ask the assistant to explain the code before you ask it to change anything. When you understand the bug yourself, it is much easier to judge whether the fix is right.
Ravindra Bagale's Tip – मराठी
Assistant ला काहीही बदलायला सांगण्याआधी code समजावून सांगायला सांगा. Bug तुम्हाला स्वतः समजला की fix बरोबर आहे की नाही ते ठरवणं खूप सोपं होतं.
Ravindra Bagale's Tip – हिंदी
Assistant से कुछ भी बदलवाने से पहले code समझाने को कहो. जब bug आपको खुद समझ आ जाता है, तब यह तय करना बहुत आसान होता है कि fix सही है या नहीं।
Python 3.13.5 and pytest 9.1.1. Starter: 4 failed, 3 passed. Fixed file: 7 passed. The AI tool itself runs on your own computer, so its words will differ from any example here.Your task: open the practice folder in your editor, ask your AI coding assistant to explain juice_price, and then ask it to fix the function so that sizes work with capital letters and extra spaces, and an unknown size raises ValueError with a message that contains size.
Setup (practice folder mango-juice)
- Create the practice folder with the name shown below, and save the two files from this section inside it.
- Create a virtual environment: on macOS or Linux run
python3 -m venv .venv. On Windows runpy -3 -m venv .venv. - Activate it: on macOS or Linux run
source .venv/bin/activate. In Windows Command Prompt run.venv\Scripts\activate.bat, and in Windows PowerShell run.venv\Scripts\Activate.ps1. - Install pytest inside the virtual environment:
python -m pip install pytest.
Starter juice_price.py ("Large" and " small " are not found, and an unknown size quietly returns None instead of an error):
PRICES = {"small": 30, "medium": 45, "large": 60}
def juice_price(size):
"""Fictional Mango Grove Juice Corner: price in rupees for one glass of mango juice."""
return PRICES.get(size)
Simple tests test_juice_price.py:
import pytest
from juice_price import juice_price
def test_small_glass():
assert juice_price("small") == 30
def test_medium_glass():
assert juice_price("medium") == 45
def test_large_glass():
assert juice_price("large") == 60
def test_capital_letters_are_accepted():
assert juice_price("Large") == 60
def test_extra_spaces_are_ignored():
assert juice_price(" small ") == 30
def test_unknown_size_is_rejected():
with pytest.raises(ValueError, match="size"):
juice_price("jumbo")
def test_empty_size_is_rejected():
with pytest.raises(ValueError, match="size"):
juice_price("")
Before you ask the AI, run python -m pytest -q in the folder. You should see 4 failed, 3 passed. That proves Python and pytest work before the AI tool is involved.
The exact prompt to try (copy it as it is):
explain-then-fix-prompts.txtPrompt 1 (explain only): Explain in simple words what juice_price does and why some tests in test_juice_price.py fail. Do not change any file yet.
Prompt 2 (fix): Now fix juice_price in juice_price.py for the fictional Mango Grove Juice Corner. Ignore capital letters and extra spaces in size, so " Large " costs 60. Raise ValueError with a message that contains size when the size is unknown or empty. Do not change test_juice_price.py.
HOW to run the explain, fix and verify loop
- Open the folder: open
mango-juicein your editor and openjuice_price.py. Any assistant from this course works, such as GitHub Copilot, Continue, Claude Code, Codex or Cursor. - Open the chat panel: open your assistant's chat and add
juice_price.pyandtest_juice_price.pyto the chat if your tool asks for files. - Ask for an explanation first: send Prompt 1 and read the answer. A good answer says that the dictionary lookup needs an exact match and that
getreturnsNonefor a missing size. - Ask for the fix: send Prompt 2. If your assistant shows a diff, read it before you accept it. If it only shows code in the chat, copy it into the file yourself.
- Read the change line by line: make sure that only
juice_price.pychanged and that the prices are still 30, 45 and 60. If you do not understand a line, ask the assistant to explain that line. - Confirm yourself: in the terminal, with your virtual environment active, run
python -m pytest -q. Expect 7 passed.
What a correct result looks like: The explanation says that the starter needs an exact size such as large and returns None for any size it does not know. The fix cleans the size with strip() and lower() and raises ValueError with size in the message when the cleaned size is not in the price list. The exact words and code style change from tool to tool and from run to run, which is fine. The result is correct only when pytest shows 7 passed.
Real pytest output after the fixed file:
pytest-after.txt....... [100%]
7 passed in 0.01s
Optional completed juice_price.py (try it yourself first)
Your assistant may use casefold() instead of lower(), or a different error message. Any version is fine if all 7 tests pass and the test file is unchanged.
PRICES = {"small": 30, "medium": 45, "large": 60}
def juice_price(size):
"""Fictional Mango Grove Juice Corner: price in rupees for one glass of mango juice."""
key = size.strip().lower()
if key not in PRICES:
raise ValueError(f"unknown size: {size!r}")
return PRICES[key]
Troubleshooting: common problems in your first AI fix
- Problem: the assistant changed the code when you only asked for an explanation. Fix: undo the change with your editor's undo, or reject the edit. In tools with modes, choose the ask or chat mode for questions, and say clearly that no file should change yet.
- Problem: the fix returns
0orNonefor an unknown size instead of raising an error. Fix: that hides the mistake from the shop. Tell the assistant that the test expectsValueErrorwithsizein the message, and ask again. - Problem: the assistant changed
test_juice_price.pyso that the tests pass. Fix: reject that change. The tests describe the correct prices, so onlyjuice_price.pyshould change. - Problem: the assistant says that the tests pass, but you have not run them. Fix: always run
python -m pytest -qyourself. An assistant can make mistakes, and only a real test run proves the result. - Problem: the assistant imports a package that you do not have. Fix: this small fix needs only plain Python. Ask the assistant to solve it without any external library, and check the official docs before you install anything it suggests.
- Problem:
pytestsays command not found or No module named pytest. Fix: activate your virtual environment, install pytest withpython -m pip install pytest, and run the tests withpython -m pytest -q.
Practice cards: English and spoken Marathi
Each card below explains one idea on its own, so you can save or revise a single card without reading the whole chapter.
Explain first, then fix
Only your test run counts
आधी समजून घ्या, मग fix करा
फक्त तुमचा test run ग्राह्य धरा
Quick quiz
1. What are the three main modes?
Inline (autocomplete), chat, and agent.
2. What must you always do with AI code?
Read it, run it, and test it before trusting it.
3. What is a "prompt"?
The request you type — a sentence or a code comment.
4. What should you never paste into a cloud assistant?
Secrets: passwords, API keys, or real customer data.
Save tokens and money
Use inline mode for small stuff (it is cheap and fast). Save chat/agent for real problems. Ask for "only the code" to get shorter answers. See more AI Coding guides.