Prompting Basics
Lesson 2 of 3
2Prompting Basics
Writing a prompt is effectively the API between you and the model: the more precise it is, the closer the result gets to what you actually want.
What the picture shows: A good prompt starts with context, then the task, then the format you want, then you read the answer and refine.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
Writing a prompt is like briefing a new colleague who has never met you. Say "write a report" and they guess everything. Say "write a one-page report for a non-technical manager, with three points and a table" and you get what you want. Clarity is the whole secret.
The prompt is the model's only input, so treat it as a spec: role and context, the task, constraints, the output format (a list, JSON or a table), and examples where you can. Split a complex task into steps, and refine the prompt by experiment, comparing results instead of settling for the first answer.
What You Need Before This Part
🧭Understanding responsible use
The four principles from Part One (transparency, understanding before copying, verification, privacy), because writing effective prompts without an ethical framework could mean more efficient harmful use.
✍️The ability to articulate what you want clearly
The skill of turning a vague idea in your mind into a clear sentence, this doesn't require technical expertise, just organized thinking about what you actually need before writing.
🔤A basic understanding of how the model responds
Knowing that the model doesn't read your intent but responds literally to what you wrote, this fundamental principle explains why clarity in a prompt isn't just a "nice suggestion" but a real necessity.
The Core Idea: Clarity Reduces Guessing
The model doesn't "read your intent", it responds literally to what you wrote. Every ambiguity in the prompt leaves room for the model to guess, and its guess might not match what you meant. This guessing isn't random, it leans on whatever pattern is most common and frequent in its training data; if your vague question statistically matches several different contexts, the model will pick the most common interpretation among them, which isn't necessarily the one you specifically meant.
1Set the context
Tell the model who you are and what you're trying to achieve ("I'm a student learning C, explain to me..."), not just an abstract question with no background.
2Specify the desired format
Do you want a paragraph, bullet points, a table, or just code? Explicitly ask for the format instead of letting the model guess it.
3Break down complex tasks
One prompt asking for five different tasks at once usually produces a shallow result for each; separate, sequential tasks produce greater depth.
4Iterate and refine
The first prompt is rarely the best, review the result, precisely identify what's missing, and ask for a specific edit instead of rewriting from scratch.
Why do these four principles actually work, not just serve as generic advice? To see this, recall from Part Three that the model predicts the next word based on every word that came before it in the same conversation, what's called the "context window." In practice, every extra word you write in your prompt enters that window and gets mathematically processed against every other word in the text through a mechanism called "attention," which shifts the probability distribution that determines the word the model picks next. This directly explains why "set the context" actually works, not just figuratively: the sentence "I'm a beginner in C" mathematically changes the probability that the model picks advanced terminology in its answer, because it's extra words exerting real influence within that same context window, not just a "nice nudge" with no real effect on the underlying computation. Likewise, "break down complex tasks" works because any single answer the model generates is practically bounded by a certain length and by a limited amount of "attention" the mechanism spreads across every part of the request; if you ask for five different tasks at once, that computational attention gets spread across five different directions and each one weakens, much the way a person's own focus weakens when juggling several tasks at once instead of sequencing them one after another.
Worked Example: From a Vague Prompt to a Precise One
| Weak prompt | Why it fails | Improved prompt |
|---|---|---|
| "Explain pointers to me" | Doesn't specify current knowledge level, desired format, or language | "I'm a beginner in C who only knows variables and functions. Explain pointers to me with a simple code example, without using advanced terms" |
| "Write me sorting code" | Doesn't specify the language, the sort type, or the request's purpose | "Explain Bubble Sort's logic step by step with a manual example on a small array, without writing the full code, I want to understand the logic first" |
Notice that the improved prompt in the table rarely appears on the first attempt, in practice it's the product of a short iteration loop: you write a prompt, read the output, pinpoint exactly where it fell short (wrong level? missing detail? wrong format?), then adjust your prompt based on that specific gap instead of rewriting it from scratch. Importantly, this improvement doesn't mean the model "learned" from your feedback permanently, it's simply seeing extra context within the same conversation that shifts the probability distribution for its next reply; in a brand-new conversation, it starts over with no trace of that feedback at all.
Figure 1, the iterative refinement loop: each edit adds new context within the same conversation, not permanent learning in the model.
Worked Example: Refining a Prompt in Three Stages
Let's trace how a real prompt evolves through three attempts, notice that each edit targets a specific gap in the previous result, not random rewriting:
| Attempt | The prompt written | What was missing | How it was improved |
|---|---|---|---|
| 1 | "Explain APIs to me" | No context (which language? which level? which type of API?) | Added context and level |
| 2 | "I'm a Python beginner, explain what a REST API is with simple examples" | Good but format unspecified, got very long paragraphs | Specified format and length |
| 3 | "I'm a Python beginner who only knows functions and libraries. Explain REST API in 5 brief points, with a simple code example using the requests library to fetch data from a free public API" | , | ✅ Precise prompt: context + level + format + length + specific example |
Myth vs. Reality
| Myth | Reality |
|---|---|
| Longer prompts are always better than short ones | Precision matters more than length, a short, specific prompt outperforms a long, scattered one. Useful additions are those that add real context or specificity, not generic filler. |
| A smarter model doesn't need good prompts, "it'll figure it out" | Even the most powerful models rely only on what's actually written, a vague prompt to a powerful model produces a more polished generic answer, but not necessarily one more useful for your specific need. |
| The model remembers my preferences across different conversations | Each new conversation starts from zero, the model only sees what's written in the current context window and retains nothing from a previous conversation (unless a dedicated memory feature is enabled). |
Real-World Applications
🐛Debugging code
Instead of asking "fix the code," describe the bug precisely ("the function returns None instead of the sorted list"), this specific context produces a far more accurate diagnosis than just pasting code.
📝Writing and editing
Ask "review this paragraph for clarity and conciseness, and suggest an alternative for each vague sentence" instead of "improve the text", specifying the type of improvement prevents random edits.
📊Data analysis
Specify the exact analysis needed: "calculate the mean and standard deviation of the sales column, then display the result in a table" is far clearer than "analyze the data."
📚Learning new concepts
Ask "explain [concept] for someone who only knows [what you already know], with one concrete example, without terms I haven't studied yet", this produces an explanation calibrated to your exact level.
Deep Dive: Why Prompts Fail and How to Improve Them
A good prompt is not linguistic magic but instructions that define context, expectations and constraints. Here we dissect why prompts fail and build the habit of improving them iteratively rather than patching outputs by hand.
Anatomy of a good prompt
Figure 2, Prompt ingredients: not every prompt needs all of them, but a missing task or context is the most common cause of failure.
Why prompts fail
| Failure pattern | Weak example | What is missing? |
|---|---|---|
| Ambiguous intent | "Explain this function" | For what level? For what purpose? |
| Over-broad question | "What is the best way to organize a project?" | What kind of project? How many people? |
| A solution without constraints | "Write a script that deletes old files" | Which folder? How old is "old"? Is permanent deletion allowed? |
In all three cases the model is not weak; the instruction is incomplete, so the model guesses your intent, and often guesses wrong. Constraints shrink the space in which the model can invent unnecessary details, which is why they reduce hallucination.
Roles: they change style, not expertise
Saying "act as a strict code reviewer" changes the model’s tone, assumptions and decisiveness, but does not grant knowledge it lacked. It can even amplify errors if the role encourages overconfidence. Use a role to choose the angle of view, then verify the substance yourself.
The improvement loop: fix the prompt, not the output
Figure 3, Iterating on the prompt: hand-fixing the output hides the real problem.
Asking for explicit critique
Models lean toward agreement and flattery by default. If you want critique, ask for it explicitly and specify its type: weaknesses, edge cases, hidden assumptions. Compare "Is this design good?" (invites flattery) with "Find three potential problems in this design and two edge cases that could break it" (invites critique).
| First prompt | Improved prompt |
|---|---|
| "Explain list comprehension in Python" | "I know for loops but have never seen list comprehension. Explain it with one example that turns a for loop into one line, without mentioning generators." |
| "Plan my study" | "I have 6 hours weekly and two subjects; suggest a four-week schedule as a table and reserve one day for review." |
Copying ready-made prompt templates without understanding why they work. A template helps once; understanding why it works (context, constraint, format) helps every time.
Try it yourself
Why does opening with “I am a beginner in C” help?
Every word in the prompt enters the context window and influences the next word through attention. Context is a computational input, not courtesy.
You asked for five different tasks in one prompt and each came back shallow. What fixes it?
Attention spreads over many directions and each one weakens. Separate, sequential tasks give more depth.
The answer is close but lacks an example. What is the smartest next step?
The first prompt is rarely the best. Review, name exactly what is missing, and ask for a targeted change.
Quick Review Flashcards
Check Your Understanding
If you wanted a difficult concept explained at a very simplified level, which part of the prompt should you specify first?
Your current knowledge level and the terms you already understand, without this context, the model might use advanced terminology that assumes knowledge you don't have yet.
Why is it recommended to edit the previous prompt based on a specific gap rather than rewriting from scratch?
Because a targeted edit preserves the parts that worked correctly and fixes only the specific issue, rewriting from scratch might lose context that was already working well and create new, different problems.
What's the difference between Zero-shot and Few-shot prompting, and when do you use each?
Zero-shot gives direct instructions with no examples, suitable for simple, clear tasks. Few-shot provides input/output examples before the actual request, suitable when you need a specific format or behavior that's hard to describe with words alone.
Find the problems in this prompt: "Write me something about algorithms, and please be smart enough to understand what I mean, and explain Python and C and compare them and quiz me on all of it."
(1) It assumes the model will read your intent, but even the strongest models rely only on what is written. (2) It gives no context, level, or desired format. (3) It bundles several tasks (explain, compare, quiz) into one prompt, so "attention" is spread thin and each part weakens. Fix: state your level, goal and format, then split the tasks into sequential prompts and refine each based on its specific gap.
Rewrite this prompt adding context, a constraint and a format: "Explain SQL".
Example: "I am a beginner who knows Excel tables; explain SELECT and WHERE with one example on a students table, in five short points, without mentioning JOIN."
Resources for this part
Sorted by kind: start with the official docs when you want the precise reference, or with an article or video when you want the explanation first.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Official docs2
Done with this lesson?
Sign in to save your progress.