Writing Effective Prompts with Prompt Engineering Techniques
This lesson explains prompt engineering, designing the input to a foundation model so it produces better output. It is the fastest and cheapest way to improve results, so it should be tried first.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the elements of a prompt: instruction, context, input data, output format and constraints.
- Distinguish zero-shot, one-shot, few-shot and chain-of-thought prompting.
- Apply good prompting practices to improve a prompt.
Elements of a prompt
A good prompt is built from distinct parts. The instruction says what to do, such as "Summarise this email in three bullet points". Context gives the model what it needs to do it well: a role, such as "You are a support agent for an airline", background information or retrieved documents. The input data is the text to work on. The output format says how the answer should look, such as JSON, a table or a word limit. A negative prompt, or constraint, says what to avoid, such as "Do not mention competitors". The following table summarises the elements.
| Element | Example |
|---|---|
| Instruction | "Summarise this email in three bullet points" |
| Context | A role ("You are a support agent for an airline"), background or retrieved documents |
| Input data | The text to work on |
| Output format | JSON, a table, a word limit |
| Negative prompt (constraint) | "Do not mention competitors" |
The following list describes how system prompts and delimiters are used.
- System prompts set persistent rules and a persona; user messages carry each request.
- Delimiters such as XML tags around documents keep instructions separate from data.
The following diagram labels the elements of one prompt.

Parts of a prompt
Prompting techniques
Prompting techniques differ in how many examples they give and how they guide the model. A zero-shot prompt asks with no examples, which works for simple, common tasks. A one-shot prompt includes one example, and a few-shot prompt includes several examples of input and desired output, which teaches the model a format or a set of labels without any training.
Chain-of-thought prompting asks the model to reason step by step before answering, which improves results on maths, logic and multi-step problems. Prompt chaining breaks a complex task into a sequence of prompts, each using the output of the one before. Prompt templates are reusable prompts with placeholders, such as {product} and {tone}, filled in for each request. The following table summarises the techniques.
| Technique | How it works |
|---|---|
| Zero-shot | Ask with no examples |
| One-shot (single-shot) | Include one example |
| Few-shot | Include several examples of input and desired output |
| Chain-of-thought (CoT) | Ask the model to reason step by step; improves maths, logic and multi-step problems |
| Prompt chaining | Break a task into a sequence of prompts, each feeding the next |
| Prompt templates | Reusable prompts with placeholders such as {product} and {tone} |
Examples teach a format and labels without any training, which is called in-context learning.
Which technique?
Good practice
The quality of model responses depends heavily on how prompts are written. The following list describes recommended practices.
- Be specific and clear; give context and describe the audience.
- Provide examples and specify output format and length.
- Ask the model to say "I do not know" when unsure.
- Break complex tasks down.
- Iterate, testing each change against sample inputs, and tune parameters such as temperature alongside the prompt.
Better prompts
Improving a prompt step by step
A retailer wants to classify customer reviews. The first, zero-shot attempt is vague:
Classify this review: "Arrived late but the jacket is lovely."The model replies with a paragraph of analysis. A better prompt adds a role, clear instructions, the allowed labels, few-shot examples and an output format:
System: You classify product reviews for an online clothing shop.
Classify the review into exactly one label: POSITIVE, NEGATIVE or MIXED.
Reply with the label only.
Review: "Terrible stitching, returned it." Label: NEGATIVE
Review: "Perfect fit and fast delivery!" Label: POSITIVE
Review: "Great colour, but the zip broke in a week." Label: MIXED
Review: "Arrived late but the jacket is lovely." Label:The model now replies MIXED, consistently. The examples taught it the labels and format without any training (in-context learning). For a question needing several steps of reasoning, such as working out a refund amount, adding "think step by step" (chain-of-thought) would improve accuracy; for a long task, splitting it into a chain of smaller prompts would help.
What is few-shot prompting?
Show answer
Including a few examples of inputs and the desired outputs in the prompt, so the model follows the pattern without any training.
Exam Tips
Remember for the exam
- A prompt with no examples is zero-shot, with one example one-shot, and with several examples few-shot.
- To improve reasoning on multi-step problems, use chain-of-thought prompting.
- A reusable prompt with variables is a prompt template.
- Telling the model what not to do is a negative prompt, or constraint.
- Persistent rules and a persona belong in the system prompt.
- Try prompt engineering before RAG or fine-tuning.