Essentials of prompt engineering
Prompt Engineering Techniques
Zero-shot, few-shot, and chain-of-thought
The story: Three ways to ask a new assistant for something:
- "Write a thank-you note to our supplier." No examples. Fine for a simple job and an experienced assistant.
- "Write a thank-you note to our supplier. Here are two we sent last year." They copy the tone and format.
- "Work out how many boxes we need for 340 cups if each box holds 24 and we need 10% spare. Show your working step by step." Writing the steps out stops them from jumping to a wrong answer.
In AI/AWS terms:
| Request | Technique | How it works | When to use it |
|---|---|---|---|
| No examples | Zero-shot | The task with no examples | Simple tasks and large, capable models |
| Two sample notes | Few-shot (one-shot with a single example) | The task plus a few input and output examples | You need a specific format or style |
| Show your working | Chain-of-thought (CoT) | Asks the model to reason in intermediate steps, for example "Think step by step" | Multi-step reasoning such as math word problems |
For the exam: No examples = zero-shot. Examples for format or style = few-shot. "Think step by step" for multi-step reasoning = chain-of-thought.
Tips
The story:
- Asking with no examples works best with experienced assistants, especially ones specifically trained to follow instructions and corrected by a manager's feedback.
- If you give examples, pick ones that are typical, varied, and clear. A few help; a whole stack becomes confusing.
- "Show your working" can be a plain instruction, or you can show a worked example of how you'd reason through a similar problem. Doing both is the strongest way to get hard problems right.
In AI/AWS terms:
- Zero-shot works better with larger models and with instruction-tuned models, including those tuned with RLHF.
- Few-shot: pick representative, diverse, clear examples. More examples usually help, but too many add noise.
- CoT can be zero-shot ("think step by step") or few-shot (worked examples that show the reasoning). Combining CoT with few-shot examples is the strongest option for complex reasoning.
For the exam: For complex reasoning, the strongest option is chain-of-thought combined with few-shot examples.
Scenario update
The story: For the finance report, the company hands the assistant its report template plus two past reports from earlier launches and says "make one like these".
In AI/AWS terms: Few-shot with the company's report template plus two example reports from earlier product launches.
For the exam: Giving example reports to match a format is few-shot prompting.