Sub topic 1
What the assistant sees: your prompt is its only view of the task
Prerequisites
This chapter assumes you can do three things:
- Write and run code in at least one language.
- Run a test suite and read its output.
- Use a chat-based or editor-integrated AI assistant, at least casually.
No other background is needed.
The prompt is the whole task
An AI coding assistant works from the text you send it. In a chat tool, that text is your message plus the earlier turns of the conversation. In an editor tool, it may also include open files or a selection, but only what the tool chooses to attach.
The assistant cannot see your project layout, your team's conventions, the error on your screen, or what you meant but did not write. It fills those gaps with a statistically likely guess. That guess is often reasonable, but it is a guess.
So the quality of the output depends on the information in the prompt. The same assistant gives a vague answer to a vague prompt and a precise answer to a precise one.
A weak prompt and a stronger one
Compare two prompts for the same job.
Weak prompt:
Write a function to clean up titles.
Stronger prompt:
Write a Python 3.10 function slugify(text: str) -> str that converts an article title into a URL slug.
Context: it will be used in a small blog tool; titles are plain ASCII.
Constraints: use only the standard library; lowercase the result; replace each run of non-alphanumeric characters with a single hyphen; no leading or trailing hyphens.
Return only the function, with no explanation.The weak prompt leaves many questions open:
- What does "clean up" mean: trimming spaces, fixing capitalization, or building a URL?
- Which language and version?
- Is a library allowed?
- Should the reply include an explanation?
The stronger prompt answers each one. It names the language, the function signature, the context, the constraints, and the output format. The assistant has far less to guess.
What a good response looks like
Given the stronger prompt, a plausible response is:
import re
def slugify(text: str) -> str:
text = text.strip().lower()
text = re.sub(r"[^a-z0-9]+", "-", text)
return text.strip("-")Each line traces back to the prompt. The re import respects "standard library only". lower() satisfies "lowercase the result". The re.sub call collapses each run of non-alphanumeric characters into one hyphen. The final strip("-") removes leading and trailing hyphens. The reply contains only the function, as requested.
You can check this directly:
from slugify_module import slugify
print(slugify("Hello, World!"))
print(slugify(" Multiple spaces "))This prints hello-world and multiple-spaces.
Common errors at this stage
- Assuming shared context. You know the project uses Python 3.10. The assistant does not, unless you say so.
- Describing the symptom, not the task. "It doesn't work" gives the assistant nothing to act on. Include the code and the exact error message.
- Trusting the first answer. A confident reply is not a correct one. Later chapters cover verification.
- Writing a long prompt that still lacks the key fact. Length is not the same as information. One missing constraint can matter more than three extra paragraphs.
How the rest of the tutorial builds on this
The remaining chapters each add one kind of information to the prompt. You will state a testable goal, add context, set constraints, show input and output examples, and request an output format. After that you will split large tasks, refine prompts from responses, verify generated code, and avoid sending secrets. The idea underneath all of them is the one in this chapter: the assistant can only use what you give it.
Exercise
You paste "Fix my login bug" into an assistant and get a generic answer about password hashing. Your real problem is a 401 error in a Flask app on Python 3.11. Why did the assistant answer the way it did, and what should the prompt include?
Show answer
The prompt said nothing about the framework, the language version, or the error, so the assistant guessed the most common meaning of "login bug". A better prompt names Flask and Python 3.11, includes the relevant code, quotes the exact 401 response or traceback, and states what the correct behavior should be.
Exercise
In the stronger slugify prompt, which phrase tells the assistant not to add commentary around the code?
Show answer
"Return only the function, with no explanation." It is the output-format instruction.