Engineering Task-Specific Prompts
This lesson explains how task-specific prompts combine clear instructions, context, examples and format constraints, tuned with inference parameters, as the cheapest and fastest way to customise a foundation model.
Learning outcomes
After completing this lesson, you will be able to:
- Write prompts with the elements of a good prompt.
- Apply zero-shot, few-shot and chain-of-thought techniques.
- Version and optimise prompts with Bedrock Prompt Management.
Elements of a good prompt
A strong prompt has several elements. A system prompt states the model's role and goal. Explicit instructions and constraints say what to do and what not to do. Relevant context, such as retrieved documents, is separated from the instructions by clear delimiters, such as XML tags, so the model does not confuse data with instructions. The required output format is specified, for example with a JSON schema, and examples show what good output looks like.
Telling the model what to do when information is missing, for example "answer 'unknown' if the document does not say", is one of the most effective ways to reduce hallucination, because otherwise models tend to invent a plausible answer.
A vague extraction prompt
Techniques
Zero-shot prompting gives instructions only. Few-shot prompting adds a handful of input-output examples, which strongly improves format adherence and classification consistency. Chain-of-thought prompting asks the model to reason step by step before answering, improving multi-step reasoning; many models also offer built-in extended reasoning. Prompt chaining splits a complex task into steps, each with its own prompt. Structured output features and tool-use schemas constrain responses to valid JSON.
The following table summarises the techniques.
| Technique | Use when |
|---|---|
| Zero-shot | Simple, well-defined tasks |
| Few-shot | Consistent format or labels needed |
| Chain-of-thought | Multi-step reasoning or calculations |
| Prompt chaining | Complex tasks that can be split into stages |
| Output schema / tool use | Machine-readable output |
The following diagram shows the parts of an invoice extraction prompt and its settings.

Prompting techniques
Managing and optimising prompts
Prompts change model behaviour as much as code changes application behaviour, so they should be versioned and tested like code. Amazon Bedrock Prompt Management stores prompts with their variables and model settings, and keeps immutable versions that applications reference. Bedrock prompt optimisation rewrites a prompt to suit a chosen model, which is useful when moving a prompt between model families.
Every prompt change should be evaluated on a fixed test set, because an edit that improves one example can cause regressions on others. Prompt Management and automated prompt testing are covered further in the CI/CD module.
From inconsistent to reliable extraction
A zero-shot prompt that extracts invoice fields returns different key names and formats on each call.
System: You extract invoice data. Return only JSON matching this schema:
{"invoice_number": string, "total": number, "currency": "ISO 4217 code", "due_date": "YYYY-MM-DD"}
If a field is missing, use null. Do not add other keys.
<example>
<invoice>INV 2231 ... Amount due: EUR 1.200,50 ... Pay by 3 March 2026</invoice>
{"invoice_number": "2231", "total": 1200.50, "currency": "EUR", "due_date": "2026-03-03"}
</example>
<invoice>{{invoice_text}}</invoice>
Settings: temperature 0, maxTokens 200The schema, a worked example, explicit handling of missing fields and temperature 0 produce consistent JSON. Fine-tuning would have been far more expensive for a problem that prompt design solved.
Which prompting technique improves multi-step reasoning?
Show answer
Chain-of-thought prompting.
Exam Tips
Remember for the exam
- Few-shot examples improve format and label consistency.
- Chain-of-thought improves multi-step reasoning.
- Specify output schemas and how to handle missing information.
- Use temperature near 0 for extraction and classification.
- Version prompts and test changes on a fixed dataset.