Prompt Engineering Techniques
Prompt Engineering Techniques
Why Is Prompt Engineering Important?
Foundation models (FMs), including large language models (LLMs), are powerful but their outputs are only as good as the inputs they receive. Prompt engineering is the practice of designing and refining the text instructions (prompts) given to a foundation model to elicit the most accurate, relevant, and useful responses. For the AWS AI Practitioner (AIF-C01) exam, understanding prompt engineering techniques is critical because it demonstrates your ability to effectively interact with generative AI services such as Amazon Bedrock and other FM-based tools. Poor prompts lead to vague, incorrect, or irrelevant outputs, while well-crafted prompts dramatically improve model performance without any retraining or fine-tuning.
What Is Prompt Engineering?
Prompt engineering is the art and science of structuring inputs to foundation models so they produce desired outputs. It involves choosing the right words, providing context, specifying the format of the response, and using various strategies to guide the model's behavior. Prompt engineering does not modify the model's weights or parameters — it works entirely at the inference layer.
Key Prompt Engineering Techniques
1. Zero-Shot Prompting
You provide the model with a task description and no examples. The model relies solely on its pre-trained knowledge to generate a response.
Example: "Classify the following review as positive or negative: 'The product broke after two days.'"
Use when the task is straightforward and the model is likely to understand it without demonstration.
2. Few-Shot Prompting
You include a small number of examples (typically 2–5) in the prompt to show the model the pattern or format you expect.
Example:
"Classify the sentiment:
Review: 'I love this!' → Positive
Review: 'Terrible experience.' → Negative
Review: 'The product broke after two days.' → "
Few-shot prompting is one of the most commonly tested techniques on the AIF-C01 exam. It improves accuracy on tasks where the model may be ambiguous about the desired output format.
3. One-Shot Prompting
A variation of few-shot where you provide exactly one example. It sits between zero-shot and few-shot in terms of guidance provided.
4. Chain-of-Thought (CoT) Prompting
You instruct the model to reason step by step before arriving at a final answer. This technique significantly improves performance on math, logic, and multi-step reasoning tasks.
Example: "A store has 15 apples. 7 are sold and 3 more are delivered. How many apples are there? Let's think step by step."
The phrase "Let's think step by step" is a classic trigger for chain-of-thought reasoning.
5. System Prompts / Role-Based Prompting
You assign a role or persona to the model to shape its behavior and tone. Many FM APIs (including Amazon Bedrock) support a separate system prompt field.
Example: "You are a senior financial analyst. Explain the concept of compound interest to a beginner."
This technique helps control the style, depth, and perspective of the response.
6. Instruction-Based Prompting
You give explicit, clear instructions about what you want the model to do, including constraints on format, length, tone, and content.
Example: "Summarize the following article in exactly 3 bullet points. Use simple language suitable for a 10-year-old."
7. Contextual Prompting
You provide relevant background information or context within the prompt so the model can generate more accurate and grounded responses. This is closely related to Retrieval-Augmented Generation (RAG), where external documents are retrieved and injected into the prompt as context.
8. Negative Prompting
You explicitly tell the model what not to do. This helps avoid common failure modes.
Example: "Explain quantum computing. Do not use technical jargon. Do not exceed 100 words."
9. Temperature and Parameter Tuning (Inference Parameters)
While not strictly a "prompt" technique, adjusting inference parameters is part of the broader prompt engineering discipline:
- Temperature: Controls randomness. Low temperature (e.g., 0.1) = more deterministic and focused. High temperature (e.g., 0.9) = more creative and varied.
- Top-p (nucleus sampling): Controls the diversity of token selection.
- Max tokens: Limits response length.
- Stop sequences: Defines where the model should stop generating.
How Prompt Engineering Works in Practice
When you send a prompt to a foundation model through a service like Amazon Bedrock:
1. The prompt text is tokenized and fed into the model.
2. The model predicts the most likely next tokens based on the prompt and its training.
3. Inference parameters (temperature, top-p, etc.) influence how tokens are selected.
4. The response is generated and returned.
Better prompts give the model better "starting conditions," leading to more relevant and accurate completions. Prompt engineering is an iterative process — you refine prompts based on outputs until you achieve the desired result.
Prompt Engineering vs. Fine-Tuning
It is important to distinguish these for the exam:
- Prompt engineering: No model modification. Fast, cheap, and flexible. Works at inference time.
- Fine-tuning: Modifies model weights with additional training data. More expensive and time-consuming but can yield deeper behavioral changes.
The exam may present scenarios where you need to choose between these approaches. Prompt engineering is typically the first and most cost-effective step.
Prompt Engineering and Amazon Bedrock
Amazon Bedrock provides access to multiple FMs (Anthropic Claude, Amazon Titan, Meta Llama, etc.) and supports prompt engineering through:
- The Bedrock playground for interactive prompt testing
- System prompts for role/persona assignment
- Inference parameter configuration
- Integration with knowledge bases for RAG-based contextual prompting
Exam Tips: Answering Questions on Prompt Engineering Techniques✅
Know the difference between zero-shot, one-shot, and few-shot prompting. The exam frequently tests whether you can identify which technique is being described in a scenario. If examples are included in the prompt, it's few-shot (or one-shot). If no examples are given, it's zero-shot.
✅
Understand chain-of-thought prompting. If a question mentions improving reasoning, multi-step problem solving, or mathematical accuracy, chain-of-thought is likely the correct answer.
✅
Remember that prompt engineering does NOT change the model. If a question asks about modifying model behavior
without retraining or fine-tuning, prompt engineering is the answer.
✅
Temperature is a key inference parameter. Low temperature = factual, consistent, deterministic responses. High temperature = creative, diverse, varied responses. Expect scenario-based questions asking which setting is appropriate.
✅
Distinguish prompt engineering from RAG and fine-tuning. RAG retrieves external knowledge and injects it into the prompt context. Fine-tuning changes the model. Prompt engineering is about crafting better instructions. The exam tests whether you can select the right approach for a given scenario.
✅
Look for keywords in exam questions: "improve output quality without retraining" → prompt engineering. "Include examples in the prompt" → few-shot. "Step-by-step reasoning" → chain-of-thought. "Assign a persona" → system/role-based prompting. "Reduce hallucinations with external data" → RAG (contextual prompting).
✅
System prompts matter. When a scenario describes setting the model's behavior globally (e.g., always respond as a medical professional), the answer likely involves system prompts or role-based prompting.
✅
Iterative refinement is expected. The exam may describe a scenario where initial outputs are poor. The correct answer is typically to refine the prompt (add constraints, examples, or clearer instructions) rather than immediately jumping to fine-tuning.