Sub topic 1
What the Assistant Sees: Your Prompt Is Its Only View of the Task
An AI coding assistant does not know your project, your goals, or your standards unless you tell it. It works from the text it receives. When a response is wrong, the cause is often missing or ambiguous input. This chapter builds a working model of what the assistant receives and how it fills the gaps. The rest of the tutorial builds on that model.
Prerequisites
This chapter assumes you have:
- Basic programming experience in at least one language. The examples use Python.
- Experience running code and tests, for example with
pytest. - Some experience using a chat-based or editor-integrated AI assistant.
You don't need to know how language models work internally. The chapter uses only the behavior you can observe.
The assistant works from what it is given
When you send a request, the assistant receives a bundle of text. Depending on the tool, that bundle may include:
- Your current message.
- Earlier messages in the same conversation.
- Files, selections, or error output that you or the tool attached.
- Hidden instructions from the tool itself, such as "you are a coding assistant".
Everything else is invisible to it. It cannot see your repository, your terminal, your teammates' conventions, or the ticket you read this morning. If a fact is not in that bundle, the assistant can only guess it.
Editor-integrated tools often attach context for you, such as the open file or the current selection. That helps, but it is a selection made by the tool, not a complete picture. Treat attached context as a bonus. Don't count on it.
What you know compared with what it sees
The gap between your knowledge and the assistant's input is the main source of poor results. The table lists common facts that feel obvious to you and are invisible to the assistant.
| What you know | Does the assistant see it? | What to do |
|---|---|---|
| The language and version you run | Only if stated or inferable from attached code | Name it, for example "Python 3.10" |
| Which libraries are allowed | No | State the allowed and forbidden libraries |
| What "done" looks like | No | Describe the expected behavior or give examples |
| The exact error you saw | Only if you paste it | Paste the full message and traceback |
| Code in other files | Only if attached | Paste the relevant parts |
| Your team's style rules | No | Summarize the rules that matter |
| Which parts must not change | No | Say so explicitly |
Later chapters cover each row in detail: goals, context, constraints, examples, and output format. Here the point is simpler. Each row is a decision the assistant will make for you if you leave it out.
A worked example: the same task, two prompts
Suppose you want a function that turns article titles into URL slugs. Here is a weak prompt and a stronger one.
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.Consider what the assistant must decide when it reads the weak prompt:
- Language. The prompt doesn't name one. The assistant may pick Python, JavaScript, or whatever your attached file suggests.
- Meaning of "clean up". It could mean trimming whitespace, fixing capitalization, removing punctuation, or building a URL slug.
- Signature. Function name, parameter type, and return type are all open.
- Dependencies. It may import a third-party library you don't have installed.
- Format. It may return a long explanation around the code, or several variants.
Each of these is a point where the assistant's guess can diverge from your intent. The stronger prompt closes most of them. It names the language and version, the signature, the purpose, the allowed libraries, the exact transformation rules, and the output format.
Here is a plausible response to the stronger prompt:
import re
def slugify(text: str) -> str:
text = text.strip().lower()
text = re.sub(r"[^a-z0-9]+", "-", text)
return text.strip("-")This satisfies each stated constraint. It uses only the standard library, lowercases the input, collapses each run of non-alphanumeric characters into one hyphen, and strips hyphens from both ends. You can check by running it:
print(slugify("Hello, World!")) # hello-world
print(slugify(" Multiple spaces ")) # multiple-spacesNotice what the prompt did not specify: what happens with non-ASCII input such as "Café". The function above turns it into "caf", because é is not in a-z. That is acceptable here, because the prompt said titles are plain ASCII. If your titles could contain accents, the prompt would have needed to say so, because the assistant had no other way to know.
How the assistant fills gaps
The assistant generates the most plausible continuation of the text it was given. When your prompt leaves something open, it picks a likely default. This has several consequences you should expect.
Defaults reflect common practice, not your project
If you don't specify a test framework, you may get unittest when your project uses pytest. If you don't specify a style, you get a typical one. Common choices are often reasonable, but they are not tailored to you.
Fluent output is not evidence of correct output
The assistant writes confident, well-formatted code whether or not it is correct. Confidence in the tone tells you nothing about whether the code runs or meets your requirements. The verification chapter covers how to check generated code. For now, adopt the habit that generated code is a draft from a capable but uninformed colleague.
Results can vary between runs
Sending the same prompt twice can produce different code. A vague prompt allows more variation, because more choices are left open. A precise prompt narrows the range of acceptable answers, so variation matters less.
Silence is not a "no"
If you don't forbid something, the assistant may do it. Common examples are refactoring code you didn't ask about, adding dependencies, and renaming things. Scope belongs in the prompt.
Edge cases that change what the assistant sees
Long conversations lose detail
The assistant can only take in a limited amount of text at once. This limit is called the context window. In a long conversation, early messages may be trimmed, summarized, or given less weight. A constraint you stated twenty messages ago may no longer shape the response. If a constraint matters, restate it, or start a fresh conversation with a compact summary.
Its knowledge has a cutoff
The assistant learned from text collected up to some date. Libraries released or changed after that date may be unknown to it or misremembered. It may call functions that were renamed or removed. Stating the library version and pasting the relevant documentation or signature reduces this risk.
Instructions can conflict
The tool's hidden instructions, earlier messages, and your current message may disagree. For example, an earlier message says "return only code" and a later one asks "explain why". The assistant has to choose, and it may not choose as you would. When you change direction, say so plainly: "Ignore the earlier format request. Now explain."
It usually cannot run your code
Unless your tool explicitly gives it the ability to execute code, the assistant is predicting what the code would do. It has not tested it. Whether the code actually works is something you establish by running it.
Attached context can leak information
Because the assistant sees whatever is attached or pasted, a selection that includes an API key or customer data sends that content to the assistant. A later chapter covers how to keep secrets and private data out of prompts. Keep the idea in mind from the start: what the assistant sees is exactly what you have shared, so you should decide that deliberately.
Common errors
| Symptom | Likely cause in the prompt | Fix |
|---|---|---|
| Code in the wrong language | Language not stated and no file attached | Name the language and version |
| Imports a package you don't use | Allowed libraries not stated | List allowed and forbidden libraries |
| Solves a different problem | Goal was vague, such as "clean up" | Describe the exact input and output behavior |
| Uses an API that doesn't exist | Version not stated, or library is newer than its knowledge | State the version and paste the documentation |
| Ignores a rule from earlier | Conversation grew long | Restate the rule in the current message |
| Rewrites more than you asked | Scope not limited | Say what must not change |
A useful diagnostic is to read your prompt as a stranger would. Imagine a skilled developer who has never seen your project and cannot ask questions. Would they know the language, the goal, the limits, and the expected output? If not, the assistant doesn't either.
Where the rest of the tutorial goes
The chapters that follow each add one kind of information to the prompt. You will state a specific, testable goal, add context, set constraints, and show examples. You will then request an output format, split large tasks into steps, iterate on responses, and verify results. The last chapters cover common failure modes, protecting sensitive data, and turning good prompts into reusable templates. All of them rest on this chapter's idea. The assistant can only use what it is given, so a good prompt is mostly a matter of deciding what to include.
Exercise
You ask an assistant, "Write a function to parse the dates in my log file," and get JavaScript that uses a third-party library. You wanted Python with only the standard library. Name three facts that were missing from the prompt, and say why the assistant could not have known them.
Show answer
The prompt did not state the language (Python), the library constraint (standard library only), or the log format and date format (which formats appear, and what the function should return). The assistant sees only the text it is given. It cannot see your project, your environment, or the log file unless you attach or paste a sample. It filled each gap with a common default, which here was JavaScript and a popular library.
Exercise
A constraint you set at the start of a long conversation, "use only the standard library", is ignored in the twentieth response. Give one likely reason and one fix.
Show answer
A likely reason is that the conversation exceeded what the assistant takes in at once, so the early message was trimmed or given less weight. The fix is to restate the constraint in the current message, or to start a new conversation with a short summary that includes it.