Prompt Engineering on AWS
Bedrock prompt techniques, guardrails, model evaluation
Effective prompting is the primary way to control foundation model behaviour on Amazon Bedrock. The exam tests understanding of prompt techniques, inference parameters, and Bedrock Guardrails for safe, accurate outputs.
Key Points
- System prompt: sets model persona, constraints, and response format — always pass via the system field
- Zero-shot: no examples; works well for simple tasks with capable models like Claude 3
- Few-shot: include 2–5 example input-output pairs in the prompt for consistent formatting
- Chain-of-Thought (CoT): "Think step by step" — improves reasoning accuracy on complex questions
- Temperature: 0 = deterministic/factual; 0.7 = balanced; 1.0 = creative/diverse
- Top-P (Nucleus sampling): limits token pool to those comprising top P% probability mass
- Top-K: limits to the K most likely next tokens — use with Top-P
- Max Tokens: controls response length — set appropriately to avoid truncation or unnecessary cost
- Bedrock Guardrails: apply filters for harmful content, topic denial, PII redaction, hallucination grounding
- Bedrock Prompt Management: store, version, and share prompt templates across your organisation
- Prompt injection mitigation: validate inputs, use Guardrails, separate system/user contexts clearly
| Parameter | Effect | Recommended Value |
|---|---|---|
| Temperature | Randomness/creativity | 0 for factual, 0.7 for conversational, 1.0 for creative |
| Top-P | Diversity of tokens | 0.9 for most tasks; lower for more focused |
| Top-K | Hard limit on token choices | 50–100 for balanced output |
| Max Tokens | Response length limit | Set to expected max output + 20% buffer |
| Stop sequences | Stop generation at a string | Use to prevent model from continuing past the answer |
Real-World Example
Amazon Q Business uses Bedrock with strict system prompts and Guardrails to ensure the enterprise AI assistant only answers questions based on company-approved knowledge bases — refusing to answer questions outside the configured topics and automatically redacting PII from responses.