Building with LLMs › Prompts and context
What is prompt engineering? A gentle guide to clear prompts
What prompt engineering means, the basic techniques the official guides share, a real test of a vague and a specific prompt, and where prompting falls short.
If you’ve used ChatGPT, Claude, or Gemini, you’ve already written a prompt, since the text you type to ask a model for something is exactly that. Perhaps you’ve also noticed that asking for the same thing in slightly different words can bring back a noticeably different answer. Prompt engineering is the name for the work that deals with that gap, and it shows up everywhere from tips for chat users to the developer docs of the big model providers.
Prompt engineering is the work of designing and refining the instructions and input you give a model so that it produces the result you want. OpenAI’s prompt engineering guide describes it as “the process of writing effective instructions for a model, such that it consistently generates content that meets your requirements.” The word that catches my eye in that sentence is consistently. One good answer often comes more easily than you’d expect, but getting a usable answer in the same shape every time takes some design.
That’s also why the term comes up so often these days. Many people now talk to models every day, and for developers, the instructions an app sends to a model have become part of its code. Newer terms such as context engineering are built on top of this one, too, so perhaps many people come back to it as the starting point.
Why the way you ask changes the answer
A large language model, or LLM, writes its answer by continuing from the text it’s given. All it knows is what it learned in training and what’s in the prompt right now. So unless the prompt says so, it doesn’t know your team’s situation, the format you want, or why you’re asking. That’s why Anthropic’s Prompting best practices asks you to think of Claude as “a brilliant but new employee who lacks context on your norms and workflows.” The same page offers a simple test, too. If a colleague who knows little about the task would be confused by your prompt, the model will be as well.
A well-known early demonstration that a prompt alone can point a model at a new task came from GPT-3. In 2020, Tom Brown and colleagues showed in Language Models are Few-Shot Learners that the model could handle a range of tasks from a few examples written into the prompt. The model was used “without any gradient updates or fine-tuning,” which means it wasn’t retrained at all. That’s why prompting is so cheap to try.
Same meeting notes, two prompts
Let’s check this with a real model. The task is turning messy meeting notes into a to-do list, and the notes are saved as notes.txt.
Weekly sync, Thu Oct 22
- Safari signup bug still open. Priya thinks it's the date picker, she'll dig in
- Launch moves from Nov 5 to Nov 12 (agreed)
- Landing page copy: Sam drafts by Mon, Alex reviews
- Someone should ask finance about the interview budget
- Alex sends recap to design today
- Next sync same time next week
I sent both prompts through Claude Code’s claude -p, which runs once without opening a chat and then exits. --tools "" turns off every tool so the model only writes text, and --system-prompt replaces the default system prompt, which is written for coding work (CLI reference). The vague version gets a single generic sentence.
claude -p "Make a to-do list from these meeting notes.
$(cat notes.txt)" --model haiku --tools "" \
--system-prompt "You are a helpful assistant." < /dev/null
# To-Do List: Weekly Sync (Thu Oct 22)
- [ ] **Priya:** Investigate the Safari signup bug (suspects the date picker)
- [ ] **Sam:** Draft landing page copy by Monday
- [ ] **Alex:** Review landing page copy after Sam's draft
- [ ] **Unassigned:** Ask finance about the interview budget
- [ ] **Alex:** Send meeting recap to design (due today, Oct 22)
- [ ] **Everyone:** Note the launch date change from Nov 5 to Nov 12 (agreed)
- [ ] **Everyone:** Attend next sync, same time next week
It isn’t a bad answer. The model found every owner and even marked the finance item as unassigned. Everything else, though, it decided on its own. It added a heading, checkboxes, and bold names, turned the launch decision and the next meeting into tasks for everyone, and wrote the due dates differently on each line. A person skimming it would be fine, but a program that has to read this list would struggle. And when I ran the same command again, the shape changed, with a different heading size and a Notes section added at the end.
For the specific version, system.txt gives the model a role and tells it why the format matters.
You turn meeting notes into action items for a small product team.
The list is pasted straight into a task tracker, so follow the format exactly.
The request in prompt.txt sets rules for the format and for missing information, adds one example, and marks the boundaries of each part with XML tags. The command then wraps the notes in a notes tag and adds them after the request.
Turn the meeting notes in <notes> into action items.
Rules:
- One line per task, in the form: - [owner] task (due: date)
- Use the owner's name from the notes. If nobody is named, write [unassigned].
- Copy due dates as written. If there is none, write (due: none).
- Leave out decisions and announcements. Only list work someone has to do.
- Output only the list, with nothing before or after it.
<example>
Notes:
- Kim to update the FAQ by Wed
- We agreed to drop the beta badge
Output:
- [Kim] Update the FAQ (due: Wed)
</example>
claude -p "$(cat prompt.txt)
<notes>
$(cat notes.txt)
</notes>" --model haiku --tools "" \
--system-prompt "$(cat system.txt)" < /dev/null
- [Priya] Investigate Safari signup bug, suspected date picker (due: none)
- [Sam] Draft landing page copy (due: Mon)
- [Alex] Review landing page copy (due: none)
- [unassigned] Ask finance about interview budget (due: none)
- [Alex] Send recap to design (due: today)
This time every line follows the format. The decision and the next meeting are left out, the task with no owner says [unassigned], and the due dates are copied as written. In the second run, only “Investigate” in the first line changed to “Dig into,” and all five lines kept the same shape. I ran both commands twice on October 27, 2026, with Claude Code 2.1.304, where --model haiku pointed to Claude Haiku 5.5. The output varies from run to run, so the details will likely differ when you try it.
The basic techniques the official guides share
Anthropic, OpenAI, and Google each publish a prompting guide, and their basics overlap a great deal. Here’s how they line up with the example above.
| Technique | What it gives the model | Where it is in the example |
|---|---|---|
| Clear, specific instructions | What to produce | The five rules |
| Context and purpose | A reason to fill gaps sensibly | “pasted straight into a task tracker” |
| Examples (few-shot) | A pattern to copy | The example inside the example tag |
| Role and system prompt | Who it is acting as | The first line of system.txt |
| Output format | The shape of the answer | - [owner] task (due: date) |
| Delimiters and XML tags | Where each part begins and ends | The notes and example tags |
Of these, the purpose may feel the least familiar. Instead of a bare “NEVER use ellipses,” Anthropic’s guide suggests adding the reason, which is that the response will be read aloud by a text-to-speech engine that can’t pronounce them. That way the model can generalize from the reason to similar cases.
On examples, Anthropic recommends three to five varied ones, and Google’s Prompt design strategies goes as far as to recommend always including few-shot examples. I used only one to keep the example short. A system prompt, for its part, is the instruction an app keeps apart from the user’s message, usually to set a role and rules. Anthropic notes that even a single sentence of role makes a difference, and in OpenAI’s API, developer messages or the instructions parameter do the same job.
One classic technique doesn’t appear in the example. Chain of thought means having the model write out the intermediate reasoning steps on the way to an answer. In 2022, Jason Wei and colleagues showed that putting examples with such steps into the prompt makes large models much better at reasoning tasks such as math word problems (Wei et al. 2022).
Try, check, and revise
A prompt is rarely right on the first try, so the guides describe the work as a loop. Anthropic’s prompt engineering overview asks you to have clear success criteria, some way to test against them, and a first draft to improve before you start. OpenAI likewise suggests building tests and evaluations that measure prompt behavior.
A check can be very small. I wrote a short Python script that counts the lines in the outputs above that match the - [owner] task (due: date) format. In the vague output, 0 of 8 lines matched, while 5 of 5 did in the specific one, and the second run showed the same gap with 0 of 11 and 5 of 5. Of course, whether the right person got the right task still needs a person, or perhaps another model, to compare the result with the notes. Even so, a small check like this tells you right away whether changing one sentence of the prompt helped.
What newer models have changed
Recent models have changed a few things as well. The first is reasoning models, which work through a problem before they answer. OpenAI’s reasoning best practices says to keep prompts for these models simple and direct, and adds that asking them to “think step by step” is unnecessary since they already reason internally. Anthropic also says a general instruction such as “think thoroughly” often brings out better reasoning than a hand-written step-by-step plan. In a sense, these models now do much of what the 2022 technique asked for on their own. The need to state the goal and the constraints clearly hasn’t changed, though.
The second is long context. Context means the whole input a model reads at once, and models now handle inputs long enough to hold several documents. For those, Anthropic suggests putting the long material at the top and the question at the end, noting that queries at the end can improve response quality by up to 30 percent in tests. Google’s guide recommends the same order for Gemini 3.
How it differs from fine-tuning and context engineering
Fine-tuning is the other common way to change a model’s behavior. It trains the model further on your own examples, so it takes data, time, and money, and the model itself changes as a result. Prompt engineering leaves the model as it is and changes only what you send. That’s why, when a task can be solved with words, prompting is the quicker thing to try first.
Context engineering is a newer term that widens the view a little. Anthropic calls it “the natural progression of prompt engineering” in Effective context engineering for AI agents, published in September 2025. It goes a step beyond writing good prompts and looks after everything the model sees at each step, including tools, outside data, and the message history.
Where it helps and where it doesn’t
Prompt engineering works best when the model already has the ability and the knowledge for the task, and only a clear picture of the result you want is missing. Summaries, extraction, sorting into categories, changing the tone of a text, and answers in a fixed format are common examples. It helps less when the model lacks the facts. No choice of words will make a model know your team’s latest policy, so that information has to go in as context. And as Anthropic’s overview points out, not every problem is best solved by prompting. Latency and cost, for example, can sometimes be improved more easily by choosing a different model.
It also helps to let go of the idea of magic words. What the official guides recommend is closer to briefing a new colleague well than to any special phrase, telling them what you want and why, and what shape you’d like it in, along with an example. An instruction tuned for one model can also land differently on the next, which is why Anthropic’s guide keeps separate notes on what to change in your prompt for each model. So whenever you switch models, I’d suggest running a small check like the one above again.
Where to start
If you’re new to this, pick one task you already ask a model to do often, and start by writing down what a good answer looks like. Then write a prompt that gives the role, the purpose, the format, and one example, and run it a few times. If the results wobble, change one thing at a time and compare. The three official guides linked above make good companions along the way. I ran these examples on October 27, 2026, with Claude Code 2.1.304, whose haiku alias pointed to Claude Haiku 5.5 on the Anthropic API (model configuration).
AI tools helped with the research for this post.