Applications of Foundation Models · Topic 4 of 7
Prompt Engineering Techniques
Learn prompt engineering concepts and techniques such as zero shot, few shot, chain of thought, negative prompts and prompt templates, and when each helps.
- 4 min
- Prompt engineering improves output by changing the input, with no model training.
- Zero shot has no examples, single shot has one, and few shot has several.
- Chain of thought asks the model to reason step by step before answering.
What it is
Prompt engineering is the practice of writing and refining the input to a foundation model so that it returns useful, accurate output. It is the cheapest way to improve results, since it needs no training and no change to the model.
A good prompt tells the model what to do, gives the context it needs, and shows what a good answer looks like.
How it works
The parts of a prompt
| Part | Purpose | Example |
|---|---|---|
| Instruction | The task to perform | Summarise the text below |
| Context | Background the model needs | The reader is a new customer |
| Input data | The content to work on | The text to summarise |
| Output format | How the answer should look | Three bullet points |
| Constraints | Limits to respect | Under 60 words, no jargon |
| Examples | Samples of wanted output | One or more worked cases |
Main techniques
| Technique | What you do | Best for |
|---|---|---|
| Zero shot | Give the task with no examples | Simple, common tasks |
| Single shot (one shot) | Give one example | When a format needs one sample |
| Few shot | Give several examples | Consistent style or format, unusual tasks |
| Chain of thought | Ask the model to reason step by step | Maths, logic and multi step problems |
| Prompt template | A reusable prompt with fill in fields | Repeated tasks at scale |
| Negative prompt | State what to avoid | Image generation, or banning unwanted content |
Zero shot, single shot and few shot
The number of examples in the prompt gives these techniques their names. More examples usually give more consistent results, but they use more tokens, so the prompt costs more and takes up context window space.
Classify the sentiment as positive or negative.
Review: The delivery was late and the box was damaged.
Sentiment: negative
Review: The staff were friendly and quick.
Sentiment:
The block above is a few shot style prompt: the first review shows the format, and the model completes the second.
Chain of thought
Chain of thought prompting asks the model to show its reasoning steps before the final answer, for example with a phrase like "think step by step". This often improves results on tasks with several steps, because the model works through intermediate reasoning.
Prompt templates
A prompt template keeps the fixed instructions and marks places for variable input, such as a customer name or a document. Templates make prompts consistent, easier to test and easier to reuse. They also help guard against prompt misuse when the user input is placed in a clearly marked field.
Context, roles and multi turn
You can set a role or persona in the instructions, such as a support agent, to shape tone. In multi turn use, earlier messages stay in the context window, so the model can follow the conversation. Long conversations use more tokens.
Latent space idea
A model has learned patterns about language and concepts in its internal representation, often called latent space. A clearer, more specific prompt steers the model toward the relevant region of what it has learned. The exam uses this idea lightly, so know that wording influences what the model recalls.
Iterating
Prompt engineering is iterative. Try a version, review the output, adjust, and test again on several inputs. Keep a record of versions so you can compare them.
What to remember for the exam
- Prompt engineering improves output by changing the input, with no model training.
- Zero shot has no examples, single shot has one, and few shot has several.
- Chain of thought asks the model to reason step by step before answering.
- Prompt templates give reusable, consistent prompts with fill in fields.
- Negative prompts say what to avoid, and are common for image models.
- More examples improve consistency but use more tokens.
- Clear instructions, context and an output format give better results.
- Prompts are refined through repeated testing.
If a question asks how to get a model to follow a specific output format, the answer is usually to add examples (few shot) or to state the format clearly.
Common mistakes
Writing vague prompts. "Tell me about sales" gives a broad answer. Name the audience, scope and format.
Using many examples when one is enough. Extra examples raise cost without always improving quality.
Mixing up few shot with fine tuning. Few shot gives examples inside the prompt. Fine tuning changes the model.
Expecting chain of thought to guarantee a correct answer. It can help, but errors can still occur.
Forgetting to test. A prompt that works on one input may fail on others.
Check yourself
What is the difference between zero shot and few shot prompting?
Zero shot gives no examples, and few shot includes several examples of the wanted output.
What does chain of thought prompting do?
It asks the model to reason step by step, which helps on multi step problems.
Why use a prompt template?
It keeps prompts consistent and reusable, with fields for variable input.
Topic 4 of 7 in Applications of Foundation Models
Test yourself on Applications of Foundation Models
The full AWS AIF-C01 question bank has 849 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.