SaveMyCert
Log in
5 of 5 free questions left today·for 30 a day
Applications of Foundation Models

Prompt Engineering Techniques: Zero-Shot to Chain-of-Thought (AIF-C01)

18 min readAIF-C01 · Applications of Foundation ModelsUpdated

Prompt engineering is the practice of writing clear, well-structured instructions so a foundation model produces the output you want, and it is the cheapest way to shape a model's behavior because it needs no training. This lesson covers Task 3.2 of the AIF-C01 exam. You will learn the building blocks of a prompt, including context, instruction, and negative prompts, and the core techniques the exam names: zero-shot, single-shot, few-shot, and chain-of-thought prompting, plus reusable prompt templates. You will see a concrete before-and-after example of improving a weak prompt, how prompt techniques differ from inference parameters such as temperature, and the benefits and best practices that raise response quality. You will then learn the risks of prompting (prompt injection and hijacking, jailbreaking, exposure, prompt leaking, and poisoning), how each one is mitigated, and why prompt-level guardrails do not replace dedicated controls such as Amazon Bedrock Guardrails. Finally, you will see how Amazon Bedrock Prompt Management uses variables, variants, a working draft, and versions to manage prompts and roll back changes safely.

What you’ll learn
  • Identify the core constructs of a prompt: instruction, context, input data, examples, and negative prompts.
  • Distinguish zero-shot, single-shot, and few-shot prompting by how many examples they provide.
  • Explain chain-of-thought prompting and when reusable prompt templates help.
  • Improve a weak prompt using specificity, concision, relevant context, and iteration, and tell a prompt change apart from an inference-parameter change such as temperature.
  • Distinguish prompt injection and hijacking, jailbreaking, exposure, prompt leaking, and poisoning, and match each to its mitigation.
  • Describe how Amazon Bedrock Prompt Management uses variables, variants, a working draft, and versions to manage prompts and roll back changes.

What Prompt Engineering Is and Its Building Blocks

Prompt engineering is the practice of designing the input you give a foundation model so it returns accurate, relevant, useful output. Because you are only changing the prompt, not retraining the model, it is the fastest and cheapest way to improve results. A well-built prompt is usually made of a few recognizable constructs.

  • Instruction — the task you want done, stated directly, such as "Summarize the review in two sentences." Clear instructions are the heart of a good prompt.
  • Context — background information the model should use, such as the document to summarize, the audience, or the role the model should play. Context grounds the answer.
  • Input data — the specific content the model acts on, for example the customer message or the text to translate.
  • Examples — sample input-and-output pairs that show the model the format or style you expect. Examples power the few-shot techniques below.
  • Negative prompts — explicit instructions about what to avoid, such as "Do not include personal opinions" or "Do not mention competitors." Negative prompts steer the model away from unwanted content.

Negative prompt versus context. Describing a situation is context, and context only implies a rule. Telling a travel-planning assistant that a traveller uses a wheelchair leaves the model to infer which suggestions are unsuitable, and it may not. An explicit negative prompt, such as "Do not suggest venues that can only be reached by stairs," names the unwanted content and targets it directly. When one specific item keeps appearing in the output, a direct exclusion instruction is the construct built for that job; background facts help the model understand the situation but do not reliably remove the item.

You rarely need all of these at once, but recognizing them helps you diagnose a weak prompt. If a model's answer is off-topic, the context may be missing; if the format is wrong, add an example; if it keeps including something unwanted, add a negative prompt.

Zero-Shot, Single-Shot, and Few-Shot Prompting

The most commonly tested techniques differ by how many examples you include in the prompt. An example is a demonstration of the task, an input paired with the desired output, that shows the model what you want.

Zero-shot prompting gives the model an instruction with no examples and relies on its built-in knowledge. For instance: "Classify this review as positive or negative: The delivery was fast and the product works great." You provide only the task and the input. Zero-shot is quick and works well for straightforward tasks a capable model already understands.

Single-shot (also called one-shot) prompting gives one example before the real task, so the model can see the expected format. You might show one review already labeled "positive," then ask the model to label a new one the same way.

Few-shot prompting gives several examples before the real task. There is no fixed number: Amazon Bedrock's prompt guidance notes that a handful can be enough for a simple task such as classification, while harder tasks need more. Each example demonstrates an input and its correct output, so the model learns the pattern from the samples and applies it. Few-shot improves accuracy and consistency on tasks where the format or the desired judgment is not obvious from a plain instruction, such as applying a specific labeling scheme or a particular writing style. The trade-off is that more examples use more tokens. The names follow the count: zero examples is zero-shot, one example is single-shot, and several examples is few-shot. Because every example adds input tokens, zero-shot is the leanest choice when a capable model already performs the task well; add examples only when testing shows the model needs them.

Chain-of-Thought Prompting and Prompt Templates

Chain-of-thought (CoT) prompting asks the model to show its reasoning step by step before giving a final answer, often by adding a phrase such as "Let's think step by step" or "Explain your reasoning, then answer." By working through intermediate steps, the model handles complex, multi-step problems, such as word problems, logic puzzles, or multi-part analysis, more reliably than when it jumps straight to an answer. The technique trades extra output tokens for better accuracy on hard tasks. Chain-of-thought addresses faulty reasoning: when an answer is wrong because the model jumped over intermediate steps, asking it to work through those steps targets the cause. Inference settings that only change how varied the output is do not add the missing reasoning (see the comparison with temperature below).

Prompt templates are reusable prompt structures with placeholders that you fill in for each request. Instead of rewriting a prompt every time, you create a template such as: "You are a support assistant. Using the following policy: {policy}, answer the customer question: {question}. Do not guess if the answer is not in the policy." The bracketed slots are filled with real values at run time. Templates make prompting consistent and repeatable across many requests, which matters when an application sends thousands of prompts. They also make prompts easier to test, share, and improve, because everyone uses the same proven structure. Templates often combine the constructs from the first section, a role, an instruction, context, and a negative prompt, into one dependable pattern that a whole team can reuse. Amazon Bedrock Prompt Management, covered at the end of this lesson, stores templates like this with named variables.

Techniques Compared and a Before-and-After Example

The table below summarizes the core techniques and when to reach for each.

TechniqueExamples in promptWhen to use
Zero-shotNoneStraightforward tasks a capable model already understands.
Single-shot (one-shot)OneWhen one example is enough to show the expected format.
Few-shotSeveralWhen the format or judgment needs a pattern the model can copy.
Chain-of-thoughtNone or a fewComplex, multi-step reasoning where step-by-step thinking improves accuracy.
Prompt templateReusable structureRepeated, consistent prompting across many requests.

A concrete before-and-after shows why technique and construction matter. A weak prompt is: "Write about our product." It is vague, has no context, no audience, and no format, so the model guesses and the output is generic.

An improved prompt applies clear instruction, context, specificity, and a negative prompt: "You are a marketing writer. Write a 50-word product description for the SoloBrew coffee maker, a compact single-cup brewer aimed at people in small apartments. Highlight its small size and one-touch operation. Use a friendly, concise tone. Do not invent technical specifications." The improved version tells the model who to be, exactly what to produce, for whom, what to emphasize, the length and tone, and what to avoid. This is prompt engineering in action: same model, far better result, achieved only by rewriting the prompt.

Prompt content versus inference parameters

A prompt technique changes what the model is told; an inference parameter changes how the model samples its reply. Temperature is an inference parameter, not part of the prompt. Lowering it makes output more deterministic and repeatable; raising it makes output more varied. It cannot do the work of prompt content:

  • It does not fix faulty multi-step reasoning; chain-of-thought does.
  • It does not keep a specific item out of the output; a negative prompt does.
  • It cannot supply requirements the prompt never stated, such as length, audience, or format; specific instructions do.

Inference parameters such as temperature, top-p, and maximum length belong to Task 3.1 and are covered in the lesson on design considerations for foundation model applications.

Benefits and Best Practices

Prompt engineering delivers four benefits with no training cost (better response quality, fast experimentation, discovery, and lightweight guardrails), and a small set of habits produces them consistently.

Benefits

  • Response quality improvement. Good prompts produce more accurate, relevant, and well-formatted answers from the same model.
  • Experimentation. Changing a prompt takes seconds and costs only the request, so you can test many variations, compare them, and keep the best one.
  • Discovery. Trying different prompts reveals what a model can and cannot do for your use case: tasks it handles well, where it struggles, and capabilities you had not planned to use. That knowledge tells you whether prompting is enough or whether you need retrieval or fine-tuning.
  • Guardrails. Instructions can set boundaries, for example "Answer only questions about our products" or "If the policy does not cover it, say you do not know." These prompt-level guardrails shape normal behavior, but they are only text the model is asked to follow. Injected or jailbreak input can talk a model out of them, so they complement dedicated controls such as Amazon Bedrock Guardrails rather than replace them.

Best practices

  • Be specific. State exactly what you want, including format, length, tone, and audience. The model cannot meet a requirement you never wrote down.
  • State the task in plain, concise wording. Phrase the instruction clearly and unambiguously. Amazon Bedrock's prompt guidance recommends placing the question or instruction at the end of the prompt, after the context and input data, for best results.
  • Give relevant context, not everything. Context that bears on the task helps; padding the prompt with every document you have breaks concision, costs input tokens on every request, and can bury the details that matter.
  • Use multiple comments. AWS lists this practice without a precise definition. The common reading, especially for code-generation assistants, is to guide the model with several short comments or instructions, one per requirement or step, rather than one long run-on request. The underlying principle is that small, separate instructions are easier for the model to follow and easier for you to adjust.
  • Provide examples when needed. Show examples when the format or judgment is not obvious from the instruction alone.
  • Experiment and iterate. Try variations, compare results, and refine, since small wording changes can noticeably change output.

Risks and Limitations of Prompting

The main risks of prompting are prompt injection (which AWS groups with hijacking), jailbreaking, exposure, prompt leaking, and poisoning. Each one attacks a different part of the system, so learn each term by what it targets.

RiskWhat happensWhere it acts
Prompt injection / hijackingInstructions embedded in input redirect the model away from the application's intended task, for example text that tells an HR-policy assistant to drop its role and write song lyrics instead.Request-time input (user message, document, web page)
JailbreakingCrafted input bypasses the model's safety rules to get restricted or harmful content it would normally refuse.Request-time input, aimed at safety behavior
ExposureSensitive or confidential data, such as another customer's records, is revealed in the model's output.Data placed in the context or learned by the model
Prompt leakingThe prompt itself, such as hidden system instructions or developer instructions, is disclosed, often because a user asks the model to repeat or reveal them.The application's own prompt
PoisoningMalicious or biased data is introduced into the data the model is trained or fine-tuned on, so its learned behavior is skewed.Training data, before deployment

Telling the near-twins apart

  • Injection and hijacking versus jailbreaking. Prompt injection and hijacking are about redirecting the task: the injected instruction may ask for something entirely harmless, just not what the application was built to do. Jailbreaking is about defeating safety rules to obtain content the model is meant to refuse.
  • Exposure versus prompt leaking. Exposure reveals sensitive or confidential data; prompt leaking reveals the prompt or system instructions. AWS treats them as separate risks.
  • Poisoning versus prompt injection. Poisoning happens in the training data, so the skewed behavior repeats across fresh sessions even when every prompt and user input looks clean. Prompt injection arrives in a specific request and affects that interaction.

The limitation behind injection, hijacking, and jailbreaking is that a foundation model does not truly separate trusted instructions from untrusted input; it treats the whole prompt as text to act on. That is why untrusted content, such as a user message or a fetched web page, must be handled carefully.

Mitigating Prompt Risks

Each prompt risk has a mitigation that matches where it acts: separate and screen untrusted input for injection and jailbreaking, keep secrets out of the system prompt and screen extraction attempts for prompt leaking, keep restricted data out of the context for exposure, and clean the training data for poisoning. Prompt wording alone is never the whole defense.

Prompt injection, hijacking, and jailbreaking

  • Delimit untrusted input. Wrap user-supplied or fetched text in clear delimiters (for example XML-style tags) and tell the model that the enclosed text is data to process, not instructions to follow.
  • Screen input with Amazon Bedrock Guardrails. The guardrail prompt attack filter detects attacks in user input before the model acts on them: jailbreaks, prompt injection, and (on the Standard tier) prompt leakage attempts. When you call the model with the InvokeModel API, you mark the user-supplied content with input tags so the guardrail evaluates that content rather than your own system instructions.
  • Keep prompt-level guardrails as a complement. Scope instructions still help, but because an attack can override them, they sit on top of a dedicated control, not in place of one.

Prompt leaking

  • Keep secrets out of the prompt. Treat the system prompt as something a determined user may eventually see. Never put credentials, API keys, or confidential business data in it; a model cannot leak what the prompt does not contain.
  • Screen extraction attempts. The Amazon Bedrock Guardrails prompt attack filter can detect prompt leakage attempts, meaning user input that tries to extract the system prompt or developer instructions (a Standard-tier capability).
  • Do not rely on "keep this secret". An instruction telling the model not to reveal its instructions is a prompt-level guardrail and can be talked around like any other.

Exposure

  • Fix it at the source. A model cannot reveal data it never received. Pass only the data the requesting user is allowed to see into the context, for example only that customer's own records. This does not depend on the model obeying an instruction.
  • Reformatting is not removal. Summarizing, condensing, or reformatting restricted records before putting them in the prompt still places their content in the context, so it can still be exposed.
  • Add an output-side second layer. The Amazon Bedrock Guardrails sensitive information filter can detect and block or mask personal data in responses. It is a useful backstop, but it depends on scanning replies, so it complements limiting the context rather than replacing it. A negative prompt such as "Do not discuss other customers" is weaker still, because the model may not obey it.

Poisoning

  • Audit training data sources. Vet where training and fine-tuning data comes from, especially public or external sources an adversary could write to.
  • Remove the cause, not the symptom. Once a model has learned poisoned behavior, input filters, negative prompts, and output masking only hide its effects in some requests. The fix is to clean the poisoned records out of the training data and retrain or re-fine-tune the model.

Broader security controls for AI systems, such as access control and data governance, are covered under Task 5.1.

Prompt Versioning and Management with Amazon Bedrock Prompt Management

Amazon Bedrock Prompt Management is the AWS feature for creating, testing, versioning, and reusing prompts, so a prompt can be changed safely and rolled back like any other application asset. A prompt that works today may be edited, and a change can quietly make outputs worse, so teams need to save known-good versions and return to them.

How it works

  • Prompts with variables. A prompt in Prompt Management is a template: its text contains variables written in double curly braces, such as {{product_name}}, that are filled with real values at run time. A prompt also carries its model choice and inference settings.
  • Variants. In the prompt builder you can create variants of a prompt, with different wording, a different model, or different settings, and compare their outputs side by side for the same test values.
  • Working draft. Editing a prompt and saving it updates the prompt's working draft. Saving does not create a version and does not change anything production is already using.
  • Versions. Creating a version takes a point-in-time snapshot of the prompt configuration. An application deploys a specific version, either by referencing it when calling the model for inference or through a prompt node in Amazon Bedrock Flows. A pinned version keeps serving the same prompt however the draft changes.
  • Rollback. Because each version is an unchanging snapshot, rolling back is simply a matter of switching the application back to an earlier version. Releasing an improvement works the same way in reverse: snapshot the improved configuration as a new version, then switch the application to it.

Prompt Management versus SageMaker Model Registry. Prompt Management versions prompts. Amazon SageMaker Model Registry versions models (trained model artifacts and their approval status). If the thing that changes is the wording or configuration of a prompt, Prompt Management is the relevant tool; if it is the model itself, Model Registry is.

Storing prompts centrally also lets teams reuse the same approved prompts instead of copying slightly different versions into different parts of the code, bringing the discipline developers already apply to source code to prompts.

Tip. Questions describe a prompt or a goal and ask for the technique or construct: how many examples a prompt contains, whether step-by-step reasoning or a reusable template fits, and whether an explicit exclusion instruction or background context targets an unwanted item. Some offer temperature as a distractor, so know what an inference parameter can and cannot change. Risk items describe an attack and ask you to name it, telling injection and hijacking from jailbreaking, exposure from prompt leaking, and poisoning from injection by where the problem acts; harder items ask for the mitigation that removes the cause, such as limiting the context or cleaning the training data, over controls that only suppress a symptom. Prompt Management items test what saving a draft, creating a version, comparing variants, and rolling back actually do.

Key takeaways
  • Prompt engineering shapes a model's output by improving the prompt, with no training, making it the cheapest way to change model behavior.
  • The core prompt constructs are instruction (the task), context (background), input data, examples, and negative prompts; describing a situation only implies a rule, while a negative prompt excludes unwanted content explicitly.
  • Techniques differ by example count: zero-shot uses no examples and the fewest tokens, single-shot uses one, and few-shot uses several to teach a pattern.
  • Chain-of-thought prompting asks the model to reason step by step, fixing skipped steps in multi-step problems; prompt templates are reusable structures with placeholders.
  • Temperature is an inference parameter, not prompt content: it changes how varied output is, but cannot fix reasoning, exclude an item, or supply unstated requirements.
  • Best practices: be specific, state the task in plain concise wording (Bedrock guidance places it after the context), give relevant context rather than everything, use multiple short comments, and iterate.
  • Prompt injection and hijacking redirect the task; jailbreaking bypasses safety rules; exposure reveals sensitive data; prompt leaking reveals the prompt; poisoning corrupts training data.
  • Mitigate by risk: delimit untrusted input and use the Bedrock Guardrails prompt attack filter (jailbreaks, prompt injection, and on the Standard tier prompt leakage); keep secrets out of system prompts; keep restricted data out of the context, with the sensitive information filter as a second layer; clean poisoned training data and retrain.
  • Prompt-level guardrails complement but do not replace dedicated controls such as Amazon Bedrock Guardrails, because injected or jailbreak input can override them.
  • Amazon Bedrock Prompt Management uses variables, variants, a working draft, and immutable versions; switching back to an earlier version is the rollback.

Frequently asked questions

What is the difference between zero-shot and few-shot prompting?

The difference is how many examples the prompt includes. Zero-shot prompting gives the model only an instruction and the input, with no examples, and relies on the model's built-in knowledge; it works well for straightforward tasks. Few-shot prompting includes several examples, each showing an input paired with the desired output, so the model learns the pattern and applies it to the new input. Few-shot improves accuracy and consistency when the format or judgment is not obvious from a plain instruction, at the cost of using more tokens. Between the two sits single-shot, also called one-shot, which provides exactly one example. The names follow the count: zero is zero-shot, one is single-shot, several is few-shot.

What is chain-of-thought prompting?

Chain-of-thought prompting is a technique that asks the model to show its reasoning step by step before giving a final answer, often by adding a phrase such as "Let's think step by step." By working through intermediate steps rather than jumping straight to a conclusion, the model handles complex, multi-step problems, such as math word problems, logic tasks, or multi-part analysis, more reliably. The trade-off is that the model produces more output, using more tokens, but accuracy on difficult reasoning tasks improves. Lowering the temperature is not a substitute: it makes output more repeatable but does not add the intermediate reasoning.

What is the difference between prompt injection and jailbreaking?

Prompt injection is an attack in which instructions embedded in a model's input, such as a user message, an uploaded document, or a fetched web page, redirect the model away from the task the application intended; AWS groups hijacking with prompt injection. The injected request can be entirely harmless, for example telling an HR-policy assistant to write song lyrics instead. Jailbreaking is crafted input designed to bypass the model's safety rules so it produces restricted or harmful content it would normally refuse. Both arrive in request-time input and both can override instructions in the prompt, which is why the Amazon Bedrock Guardrails prompt attack filter, which detects jailbreak and prompt injection attempts (and, on the Standard tier, prompt leakage attempts) in user input, is used alongside prompt-level instructions and delimiting of untrusted text.

What is a prompt template?

A prompt template is a reusable prompt structure with placeholders that you fill in for each request, instead of writing a new prompt every time. For example, a template might read: "You are a support assistant. Using the following policy: {policy}, answer the customer question: {question}." The bracketed slots are replaced with real values at run time. Templates keep prompting consistent and repeatable across many requests, make prompts easier to test and share, and let a whole team reuse the same proven structure. They often combine several prompt constructs, such as a role, an instruction, context, and a negative prompt, into one dependable pattern. On AWS, Amazon Bedrock Prompt Management helps store and version such prompts.

What is Amazon Bedrock Prompt Management?

Amazon Bedrock Prompt Management is the AWS feature for creating, testing, versioning, and reusing prompts. Each prompt is a template with variables in double curly braces, such as {{product_name}}, plus its model and inference settings. In the prompt builder you can create variants with different wording or models and compare their outputs. Saving an edit updates the working draft only; creating a version takes an immutable point-in-time snapshot that an application deploys through inference calls or a prompt node in Amazon Bedrock Flows. Production keeps using its pinned version until you point it at another one, so rolling back means switching to an earlier version. It versions prompts, whereas Amazon SageMaker Model Registry versions models.

What is the difference between exposure and poisoning in prompt engineering?

Exposure is sensitive or confidential data, such as another customer's records, being revealed in a model's output; it is distinct from prompt leaking, which reveals the prompt or system instructions themselves. The at-source fix for exposure is to pass only data the user is allowed to see into the context, because summarizing or reformatting restricted data still exposes it; an output filter such as the Amazon Bedrock Guardrails sensitive information filter is a second layer. Poisoning is malicious or biased data introduced into the data a model is trained or fine-tuned on, so the skewed behavior repeats across sessions even when prompts and inputs look clean. Its fix is to audit and clean the training data and retrain, since input filters, negative prompts, or output masking only suppress the symptom.

Are prompt instructions enough to keep a model safe?

No. Instructions such as "Answer only questions about our products" are useful prompt-level guardrails that shape a model's normal behavior, but they are only text the model is asked to follow, and prompt injection or jailbreak input can override them. They complement, rather than replace, dedicated controls such as Amazon Bedrock Guardrails, whose prompt attack filter screens user input for jailbreak and injection attempts and whose sensitive information filter can block or mask personal data in responses. Data that a user must never see should be kept out of the prompt's context entirely, and secrets such as credentials should never be placed in a system prompt, because prompt leaking can reveal it.

Source

This lesson covers the "Applications of Foundation Models" domain of the official AIF-C01 exam guide. Vendors revise their guides — check the source for the current version.

Test yourself on this topic
Practice now

Sign up free to mark lessons complete, bookmark topics and track your exam readiness.

Spotted a mistake in this lesson?