← Back to writing

Understand · Scope: global engineering practice · Learning AI 2/8

How to write a prompt: clear task, examples and separated data

The second note in the series: what a good prompt contains, why examples work so well, how to keep instructions apart from data, and why prompts deserve tests.

This article was prepared with AI assistance, based on the sources listed at the end.

The part of the window you control

The first note described the context window: everything the model sees when it writes an answer. The prompt is the part of that window you write yourself. Whatever it leaves out, the model fills in with its most likely guess.

Writing a good prompt is therefore less about magic phrases and more about removing guesswork: who is this for, what exactly should happen, what does a good result look like?

Write it for a smart newcomer

Anthropic’s documentation suggests imagining the model as a brilliant but new employee who does not know your norms or workflows. Its test is practical: show the prompt to a colleague with little context and see whether they could follow it. If they would have questions, so does the model.

In practice that means stating the audience, the task, the constraints and the expected output. Google’s Gemini guide treats constraints as a separate ingredient of a prompt for the same reason: the model cannot respect limits you never wrote down.

Show what good looks like

A few examples often teach more than a paragraph of instructions. The GPT-3 paper made this widely known in 2020: a large enough model could take on new tasks from a handful of examples in the prompt, without being retrained. Prompts with a few examples are called few-shot prompts; prompts without any are zero-shot.

Google’s guide goes as far as recommending that you always include few-shot examples, and Anthropic calls examples one of the most reliable ways to steer format, tone and structure. Use examples that differ from each other, so the model learns the pattern rather than copying a single answer.

Keep instructions and data apart

Most real prompts mix your instructions with material the model should work on: a document, a diff, a customer email. Anthropic recommends wrapping the different parts in XML-style tags so the model can tell them apart, which matters most when a prompt combines instructions, context, examples and variable input.

The template below puts the pieces together. The diff sits inside its own tags, which makes clear that it is something to analyse, not a list of new instructions. That separation helps, but it is not a security boundary; the last note in the series looks at prompt injection.

Role and contextYou review pull requests for a payments service.TaskSummarise the risks for the on-call engineer.Rules and limitsAt most five points; say so if there is no risk.ExamplesOne good bullet shows the expected form.Input data, in tags<diff> … </diff> is material, not instructions.Output formatA list, most severe first.
Not every prompt needs all six parts, but each one answers a question the model would otherwise have to guess.
const prompt = `You review pull requests for a payments service.
Summarise the risks in the diff for the on-call engineer.

Rules:
- At most five bullet points, most severe first.
- If nothing is risky, answer "No risk found".
- Ignore formatting and naming.

<example>
- Retries now run without a limit: a failing card could be charged repeatedly.
</example>

<diff>
${diff}
</diff>`;

Ask for the reasoning when the task needs it

For multi-step problems it helps when the model works through intermediate steps before answering. Wei and colleagues showed in 2022 that including a few worked examples with step-by-step reasoning markedly improved large models on arithmetic, commonsense and symbolic tasks; with eight such examples, a 540-billion-parameter model set a new record on a benchmark of maths word problems.

Many current models have a built-in reasoning or thinking mode, and provider documentation now covers when to use it. The principle is the same: for a hard task, leave room for the steps and do not demand the answer in one line.

Treat prompts like code

The short course by Isa Fulford of OpenAI and Andrew Ng teaches prompt writing as an iterative process: try, look at the output, adjust. That works best with a small set of test inputs that you rerun after every change, including the awkward cases.

Keep prompts in version control, change one thing at a time and write down why. The next note moves from text to numbers: embeddings and vector databases.

References

  1. Anthropic documentation: Prompting best practices
  2. Google Gemini API documentation: Prompt design strategies
  3. DeepLearning.AI: ChatGPT Prompt Engineering for Developers (Isa Fulford, Andrew Ng)
  4. Brown et al.: Language Models are Few-Shot Learners (arXiv, May 2020)
  5. Wei et al.: Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (arXiv, January 2022)