Beginner⏱ 20 min⚑ 70 XP🧩 5-question quiz

Prompt Engineering Fundamentals

Understand how a model reads your prompt, then master the levers of a good one: goal, context, audience, examples, format, constraints and iteration.


In Module 01 (AI Foundations) you saw that a large language model (LLM) is, at its core, a system trained to predict the next piece of text. That one fact explains most of what makes a prompt good or bad. The model has no access to your intentions, your files, your company or the conversation you had yesterday. It sees only the text (and images, audio or files) you put in front of it, and it continues from there.

Imagine handing a brilliant new colleague a sticky note that says "make a slide deck about sales." They have never met your team, do not know the audience, and have no idea whether you want three slides or thirty. Whatever they produce will probably miss. Spend two minutes explaining the goal, the audience, the key numbers and what "good" looks like, and the same colleague does excellent work. Prompt engineering is that two-minute briefing. It is less about magic phrases and more about clear communication with a capable collaborator who starts from zero.

This lesson first looks at how a model actually reads a prompt, then works through the levers that matter on any task.

How a model reads your prompt

Tokens, not words

Models do not read characters or words. Text is split into tokens: frequent words are a single token, rarer words are broken into sub-word pieces, and spaces and punctuation count too. As a rough rule of thumb, one token is about three quarters of an English word, though the ratio is worse for code, numbers and many non-English languages. Tokens matter to you for three practical reasons: pricing is per token, the context window (how much the model can consider at once) is measured in tokens, and odd tokenization explains some classic failures, such as miscounting letters in a word.

Try typing a sentence, a URL and a line of code into the widget below and compare the counts.

Next-token prediction and sampling

Given everything in the context so far, the model computes a score (a logit) for every token in its vocabulary. A softmax turns those scores into probabilities:

pi=exp⁑(zi/T)βˆ‘jexp⁑(zj/T)p_i = \frac{\exp(z_i / T)}{\sum_j \exp(z_j / T)}

where ziz_i is the logit for token ii and TT is the temperature. The model then picks a token, appends it, and repeats. A quick worked example: with three candidate tokens whose logits are 2, 1 and 0, temperature T=1T=1 gives probabilities of about 0.67, 0.24 and 0.09; at T=0.5T=0.5 the top token's share rises to about 0.87; at T=2T=2 it falls to about 0.51. With low temperature, probability piles onto the top choice and output becomes near-deterministic. With high temperature, the distribution flattens and less likely tokens get picked more often, which reads as "creative" or, past a point, incoherent.

Two practical consequences follow. First, the same prompt can produce different answers, because sampling can take a different path at token five and the rest of the answer follows from there. If you are comparing two prompts, run each a few times before deciding which is better. Second, temperature is a minor lever compared with the prompt itself. Many chat apps do not expose it, and several reasoning-model APIs fix or restrict sampling parameters, so check your provider's documentation rather than relying on it.

Messages and roles

Chat models receive a structured conversation rather than one blob of text. The diagram shows what typically sits in the context window when you press Enter.

Rendering diagram…

Everything feeding into the context window competes for the model's attention, and anything not in it does not exist for the model. The system prompt (set by the app or by you in custom instructions or an API call) carries standing rules. Your user message carries the task. Knowing this helps you debug: if a chat assistant behaves oddly, the cause may be custom instructions or a long earlier conversation you forgot was still in context.

The levers of a good prompt

1. State the goal, not just the task

"Summarize this report" is a task. "Summarize this report so our CFO can decide in two minutes whether to fund phase two" is a goal. The goal tells the model what to optimize: which details matter, what to leave out, and how to judge its own draft. A useful test is the contractor test: if you handed your prompt to a smart human contractor, would they need to ask follow-up questions? If yes, answer those questions in the prompt.

2. Give context and source material

The model does not know your situation. Useful context includes:

  • Background: "I'm preparing for a renewal negotiation with a supplier who raised prices 12%."
  • Source material: paste the actual document, error message, data sample or policy instead of describing it from memory.
  • What you already tried and why it did not work.
  • Definitions of anything internal: project names, acronyms, house style.

When you paste long material, separate it clearly from your instructions, for example with XML-style tags such as <report> and </report> or with Markdown headings. This helps the model tell instructions apart from content it should operate on, and it lets you refer to pieces by name ("using only the figures in <report>..."). The next lessons go much deeper on choosing and arranging context.

3. Name the audience and the voice

Executives, engineers, customers and ten-year-olds need different answers. Naming the audience changes vocabulary, depth and what gets explained. A role ("Act as a skeptical peer reviewer", "You are a patient maths tutor") is a related lever: it frames perspective and style. Keep expectations realistic. A role shapes how the model writes; it does not grant knowledge or facts. "You are a world-class lawyer" without the facts of your case still yields generic advice.

4. Show examples

Describing a style in words is hard; showing it is easy. One or two examples of what you want communicate length, rhythm, tone and structure at once:

Write a product description for a stainless steel water bottle.
Match the style of this example:

<example>
Trail Mug: Built for cold mornings and long hikes. Double-walled,
dishwasher-safe, and tough enough to survive a drop onto granite.
Holds 350 ml of whatever gets you up the mountain.
</example>

Caution: models over-copy examples. With one example you may get the same sentence structure back with nouns swapped. Several varied examples generalize better, which the next lesson covers as few-shot prompting.

5. Specify the format

Say what the output should look like: a table with named columns, a numbered list, an email with a subject line, a paragraph under 100 words, or JSON matching a schema. Format instructions save editing time and matter most when output feeds another tool. Positive instructions work better than negative ones: "write in flowing paragraphs" beats "don't use bullet points", because it tells the model what to do instead of only what to avoid.

6. State constraints, with reasons

Constraints include length, reading level, spelling variety, things to exclude and must-include points. Wherever you can, add the why. Compare:

  • "Never use acronyms."
  • "Avoid acronyms, because this goes to new customers who will not know our internal terms."

The second version lets the model generalize: it will also avoid internal product codenames, which your rule never mentioned. Modern models follow instructions closely, often literally, so explaining intent is the best way to cover cases you did not anticipate.

7. Iterate with precise feedback

Expert users rarely expect a perfect first answer. They read the output, notice what is off and give targeted feedback:

  • "Good, but halve the length and drop the jargon."
  • "Option two is closest. Give me three more in that direction."
  • "You assumed Python 2. We use Python 3.12; please update."

"Make it better" gives the model nothing to work with. When you notice yourself making the same correction repeatedly, fold it into your saved prompt.

Rendering diagram…

The loop above is the core habit: run the prompt more than once, diagnose the gap as a missing lever rather than bad luck, fix the prompt, and save what works.

A worked example

Weak prompt: "Help me write an email to my landlord."

Strong prompt:

Help me write a polite but firm email to my landlord.

<context>
The kitchen tap has leaked for three weeks. I reported it by phone on
3 March and by text on 10 March. Nobody has come. My lease says repairs
will be handled "within a reasonable time".
</context>

Goal: get a repair scheduled this week without damaging a relationship
I want to keep (I plan to renew the lease).

Format: under 150 words, with a subject line. End with a specific request
for a date and time. Plain, friendly British English.

Notice what each part does. The context gives facts the model cannot guess. The goal ("renew the lease") explains why the tone must stay friendly. The format makes the result usable without editing. It takes about a minute to write, and that minute pays for itself.

Common pitfalls and misconceptions

  • Magic-phrase thinking. Tricks like offering the model a tip or threatening it are folklore from older models. Clear goals and context matter far more.
  • Overloading with capital letters and "MUST". Modern models follow instructions closely; shouting can make them over-apply a rule. Calm, explained instructions work better.
  • Judging a prompt on one sample. Because output is sampled, one good or bad run tells you little.
  • Describing instead of pasting. Paraphrasing a document or error from memory throws away detail the model needs.
  • Assuming the model remembers. A new chat starts empty unless the app adds memory or project files. Check what your tool actually carries over.
  • Trusting fluency. A well-written answer is not necessarily a correct one. The evaluation lesson later in this module covers verification.

Hands-on exercise

Pick a real task from your week, such as an email, a summary, a plan or an explanation.

  1. Write the laziest one-line prompt you can for it. Run it twice and save both outputs. Note how much they differ.
  2. Rewrite the prompt using at least five of the seven levers: a goal, real pasted context in tags, the audience, one example if style matters, a format, and constraints with reasons.
  3. Run the new prompt twice. Write down three specific differences from the lazy version.
  4. Give one round of precise feedback on the better output and note the improvement.
  5. Save the final prompt in a document called "Prompt library" with a one-line note on when to use it.

Expected outcome: the rewritten prompt produces output you could use with light editing, and the two runs of it agree with each other more than the two lazy runs did.

Key takeaways

  • A model sees only what is in its context window and predicts tokens one at a time, sampling from a probability distribution, so outputs vary between runs.
  • Tokens drive cost, context limits and some strange failures; temperature reshapes the next-token distribution but matters far less than the prompt.
  • The strongest levers are a clear goal and real context; then audience, examples, format and constraints.
  • Explain the reason behind constraints so the model can generalize your intent.
  • Iterate with specific feedback, test prompts over several runs, and keep a personal prompt library.

The next lesson builds on these levers with techniques for harder tasks: few-shot examples, decomposition and chaining, structured outputs, and how to prompt the reasoning models that now handle most complex work.

Further reading

  • Anthropic, "Prompt engineering overview" and "Claude prompting best practices", in the Claude documentation (docs.anthropic.com / docs.claude.com).
  • OpenAI, "Prompt engineering" guide, in the OpenAI platform documentation.
  • Google, "Prompt design strategies", in the Gemini API documentation.
  • Holtzman et al., "The Curious Case of Neural Text Degeneration" (2019): why sampling strategy shapes output quality.

Save your progress and earn XP

Create a free account to take the quiz, track progress and unlock badges.