Prompting Well
You learn a repeatable way to write prompts: set a role, state the task, give examples, define the format, and iterate. You also learn the common ways prompts fail and how to fix them.
You Will Be Able To
- Write a prompt with a clear role, task, context, and output format.
- Use examples in a prompt to show the model the pattern you want.
- Structure a long prompt with labeled sections and delimiters.
- Improve a prompt through small, tested iterations.
- Recognize common failure patterns and apply a fix for each.
What A Prompt Is And Why Wording Matters
A prompt is the text you give a model so that it can continue it. In week 5 we saw that a language model predicts likely next tokens. Your prompt sets the starting point, so the words you choose steer which continuation is likely. A vague prompt leaves the model to guess your intent, and a clear prompt narrows the guess.
A useful mindset is to treat the model like a capable new colleague who knows nothing about your situation. They read quickly and write well, but they cannot see your screen, your goals, or your audience unless you say so. Most weak outputs come from missing information, not from a weak model.
Prompting is a practical skill, not a trick. There are no magic phrases. What works is clarity, relevant context, and testing. The sections below give a set of habits you can apply to nearly any task.
Roles And System Instructions
Most chat tools and APIs let you separate instructions into messages with roles. The system message sets standing rules for the whole conversation, such as tone and limits. The user message holds the current request. The assistant message holds the model's replies. In an API call, you send these as a list, which week 10 covers.
Giving the model a role in the system message focuses its style and level of detail. Compare You are an assistant with You are a patient tutor who explains concepts to adult beginners using everyday examples. The second tells the model who the reader is, which shapes vocabulary and depth. A role also helps with scope: state what the assistant should and should not do, for instance that it answers only from the supplied text.
Keep roles honest and specific. A role does not give the model new knowledge. It only changes how existing knowledge is presented.
Be Clear: Task, Context, Format
Strong prompts usually contain four parts. State the task as a direct instruction. Give the context the model needs, such as the audience, the purpose, and any facts. Describe the output format, such as a table, a list of five items, or valid JSON. And add constraints, such as length, tone, or words to avoid.
Say what you want instead of listing what you do not want. A sentence like Do not use jargon leaves open what to write instead. Write in plain language a high school student would follow gives a target. Positive instructions are easier for a model to follow, and for a reader to check.
Be specific about size and shape. Write a summary is open-ended. Write a summary of 3 bullet points, each under 20 words, for a busy manager is testable. If you can imagine a person checking the output against your instruction and giving a clear yes or no, your prompt is specific enough.
- Task: the action, stated directly.
- Context: audience, purpose, facts the model needs.
- Format: the shape of the answer.
- Constraints: length, tone, scope.
| Part | Question it answers |
|---|---|
| Task | What exactly should be done? |
| Context | What does the model need to know? |
| Format | What should the answer look like? |
| Constraints | What to avoid or limit? |
Show Examples
Examples are often more powerful than descriptions. Giving a few input and output pairs is called few-shot prompting. Giving none is zero-shot, and giving one is one-shot. The model picks up the pattern, including format, tone, and level of detail, without a long explanation.
Choose examples that cover the range of your cases, including an awkward one. Keep their format identical, since the model will copy it. If all your examples are positive reviews, the model may lean toward calling the next review positive. Two to five good examples are usually enough.
For tasks that need several steps of reasoning, ask the model to work through the problem before giving the final answer. This is called chain-of-thought prompting. A phrase such as Think through the steps, then give the answer on a final line often improves accuracy on math and logic tasks. Some current models reason on their own before answering, so test whether the extra instruction still helps with the model you use.
| Style | What you give the model |
|---|---|
| Zero shot | Instructions only |
| One shot | Instructions and one example |
| Few shot | Instructions and several examples |
Structure Long Prompts
When a prompt contains instructions, documents, and examples, clear structure prevents confusion. Separate parts with labels or delimiters, such as headings, triple quotes, or tags like <document> and </document>. Put the material first and the question after it when working with long text, since the question stays fresh in the context window.
A good layout moves from general to specific: role, task, rules, examples, the input, then a reminder of the output format. Name each part so that you can find and edit it later. This also makes it safe to paste untrusted text, because the model can tell where your instructions end and the data begins, though it does not make the model immune to instructions hidden in that data. Week 8 discusses that risk, called prompt injection.
Ask for structured output when a program will read the answer. For example, request JSON with named fields and say that nothing else should be returned. Then check the result in code, because models can still break the format occasionally.
Iterate Like An Engineer
Your first prompt is a draft. Improve it with a loop. Run the prompt on several real inputs. Read the outputs critically and find the pattern in the errors. Change one thing in the prompt. Run again and compare. Changing many things at once hides which change helped.
Build a small test set of 5 to 10 inputs, including hard ones, and keep it. Each time you edit the prompt, run the whole set. This habit is the seed of the evaluation methods in week 8. Save versions of your prompts with short notes, the way you would save code.
When an answer is wrong, ask the model to explain its reasoning or to show which part of the source text it used. This often reveals a misunderstanding that you can fix by clarifying the instruction. You can also ask the model to critique its own draft against your criteria and then revise it, a simple form of self-review.
- Write a first prompt
- Run on test cases
- Find failures
- Change one thing
- Run again
Treat prompts as drafts that you test.
Common Failure Patterns And Fixes
A handful of problems account for most poor results. Learn to recognize them, and the fix is usually short.
Remember that the model's settings from week 5 also matter. A lower temperature gives steadier results when you need consistency. If a prompt is long and a rule seems ignored, move it closer to the end or repeat it once. Finally, know the limit of prompting. If a task needs facts the model never saw, such as your company policies, no wording will supply them. That is the case for retrieval and tools, which are the subject of weeks 7 and 9.
- Vague output: add audience, length, and format. Show an example.
- Invented facts: supply the source text and say to answer only from it, and to reply that the answer is not given if it is missing.
- Ignored instruction: shorten the prompt, state the rule once clearly, and place it near the end.
- Wrong format: provide a sample of the exact format and ask for nothing else.
- Too agreeable: ask for the strongest counterargument, or ask the model to find flaws in your plan.
- Inconsistent results: lower the temperature and add examples.
Key Terms
- Prompt
- The text given to a model that sets the starting point for its response.
- System message
- A message that sets standing rules and a role for the whole conversation.
- Zero-shot prompting
- Asking a model to do a task with instructions only and no examples.
- Few-shot prompting
- Including a few input and output examples in the prompt to show the pattern.
- Chain-of-thought
- Asking the model to work through intermediate steps before giving a final answer.
- Delimiter
- A marker such as triple quotes or tags that separates parts of a prompt.
- Structured output
- An answer in a defined format such as JSON so that a program can read it.
- Prompt injection
- Instructions hidden in input text that try to override the developer's instructions.
- Iteration
- Improving a prompt through repeated small changes tested on the same inputs.
Exercise: Improve A Prompt On A Test Set
- Choose one real task from your work or study, such as summarizing meeting notes into action items. Collect 6 real or realistic inputs, including one messy case.
- Write the simplest possible prompt, for example Summarize these notes. Run it on all 6 inputs in a free chat assistant and save the outputs.
- Score each output from 1 to 5 against two criteria you choose, such as accuracy and usefulness. Write the scores in a small table.
- Rewrite the prompt with a role, audience, constraints, and an exact output format. Run it on the same 6 inputs and score again.
- Add two examples to the prompt and run once more. Record the scores.
- Write a short note on which change helped most and which failure patterns from the document you saw. Keep all three prompt versions.
Further Reading
- Prompt engineering overview, Anthropic documentation, docs.anthropic.com
- Prompt engineering guide, OpenAI documentation, platform.openai.com
- Chain-of-Thought Prompting Elicits Reasoning in Large Language Models, Wei et al., Google, 2022
- Language Models are Few-Shot Learners, Brown et al., OpenAI, 2020
- Prompt Engineering Guide, DAIR.AI, open online guide