Skip to content

Prompt engineering techniques, with examples

Zero-shot, few-shot, chain-of-thought and prompt templates with worked examples, plus Bedrock Prompt Management and the prompt injection risks to plan for.

8 min readBy AI Guru AcademyFacts last checked

By AI Guru Academy

In short

Prompt engineering is the practice of shaping the text you send to a large language model so it returns the response you need. The core techniques are zero-shot, single-shot and few-shot prompting, chain-of-thought, and reusable prompt templates. On AWS, Amazon Bedrock Prompt Management stores templates with variables, variants and versions. Every prompt that accepts user text also needs a plan for prompt injection.

What goes into a well-built prompt?

A prompt can contain four parts: an instruction, context, examples and the input text. AWS describes the instruction as telling the model what to do, and the input as the text it works on. Context adds information that guides how the model uses that input.

AWS's prompt design guidance adds three habits that make a visible difference:

  • Put the instruction or question at the end. AWS says this helps the model work out which information it has to find.
  • Use output indicators. State the form of the answer, such as "in one sentence" or "only output the year".
  • Give a default answer. Telling the model to reply "I don't know" when unsure helps stop answers that sound right but have low confidence.

Models called through the API do not remember earlier requests. If the model needs the previous turn, it has to be in the current prompt.

Negative prompts are mainly an image-generation idea. Amazon Titan Image Generator, for example, accepts a separate negative text field describing what not to include. AWS advises listing the unwanted item itself, such as "mirrors", rather than writing "no mirrors".

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

The difference is how many worked examples you include. AWS defines a shot as one paired example input and desired output. A zero-shot prompt has none, a single-shot prompt has one, and a few-shot prompt has several. AWS also calls few-shot prompting in-context learning, because the model learns the pattern from the prompt without any training.

The examples below use a fictional retailer, Larchmont Outdoor, sorting customer messages.

What is the difference between zero-shot, single-shot and few-shot prompting?
TechniquePrompt (shortened)What it adds
Zero-shotClassify this message as Billing, Delivery or Product. Message: My tent arrived without poles. Answer with one word.Instruction, named choices and an output indicator only
Single-shotExample: "I was charged twice" = Billing. Now classify: My tent arrived without poles.One example of the pattern
Few-shot"I was charged twice" = Billing. "Where is my parcel?" = Delivery. "The zip broke on day one" = Product. Now classify: My tent arrived without poles.Several examples covering each label

AWS suggests that 3 to 5 examples can be enough for simple tasks such as text classification, that harder tasks benefit from more, and that examples similar to real-world data improve results. Note that naming the choices matters even in zero-shot: AWS shows a classification prompt drifting into a free-form summary when the categories are not listed.

How does chain-of-thought prompting work?

Chain-of-thought asks the model to work through a problem in steps before giving the answer. AWS describes it as breaking a complex question into smaller, logical parts, and its Bedrock guidance shows that adding a phrase such as "Think step-by-step to come up with the right answer" can help on complex tasks.

Example for Larchmont Outdoor's returns desk:

  • A customer bought 3 sleeping bags and returned 1. Each bag earns 40 loyalty points, and returns remove the points for that item. How many points should the customer have?
  • Think step-by-step to come up with the right answer.

A good response lists the steps: 3 bags earn 120 points, the return removes 40, so the customer keeps 80. The visible steps also make errors easier to spot. Chain-of-thought adds output tokens, so use it where reasoning matters, not for one-word classifications.

What is a prompt template?

A prompt template is a fixed prompt layout with placeholders for the parts that change. AWS describes a template as specifying the formatting of the prompt with exchangeable content, which may include instructions, few-shot examples, and context and questions for a use case.

A template for the classifier above might read:

  • You sort customer messages for {{company}}.
  • Choose one label: {{labels}}.
  • Examples: {{examples}}
  • Message: {{message}}
  • Answer with the label only. If none fits, answer Unknown.

Templates keep prompts consistent across teams and make testing repeatable, because only the variables change between runs.

How does Amazon Bedrock Prompt Management handle versions?

Prompt Management lets you create, save and reuse prompts, with versions you can deploy. Its building blocks, as AWS defines them:

  • Variables are placeholders, filled in when you test the prompt or at runtime.
  • Prompt variants are alternative configurations of the prompt, including its message, the model or the inference settings. You can compare variants side by side and keep the best one.
  • The prompt builder is the Bedrock console tool for creating, editing and testing prompts and variants visually.
  • Drafts and versions. Saving a prompt creates a draft you keep editing. A version is a snapshot taken when you are happy with a configuration, so an application can switch between known versions.

You use a stored prompt by naming it when you run model inference, or by adding a prompt node to an Amazon Bedrock Flows flow. When creating or editing a prompt you can also turn on prompt caching for supported models. Bedrock additionally offers prompt optimization, which rewrites a prompt for a chosen model.

What are the best practices?

Treat prompts like code: write them clearly, test them and keep them under version control.

  • Be specific and concise. AWS says Bedrock models work best with simple, straightforward instructions, and that inconsistent or unclear prompts lead to undesirable responses.
  • Balance detail. AWS notes that a prompt that is too simple may lack context, while one that is too complex may confuse the model.
  • Experiment, then confirm. AWS recommends a development set for trying changes and a separate hold-out test set used only to verify the final prompt.
  • Tune inference parameters. A lower temperature gives more deterministic responses; a maximum length keeps short tasks short.
  • Add guardrails. Amazon Bedrock Guardrails evaluates inputs and model responses against your policies, whichever model you use.

What are the risks of prompt engineering?

The main risk is that user input is also a prompt, so an attacker can try to override your instructions. AWS prescriptive guidance lists common prompt injection attacks, and they map onto the terms in the AIF-C01 exam guide:

What are the risks of prompt engineering?
Exam termWhat it looks likeExample from AWS guidance
ExposureThe model reveals hidden instructions or dataAsking it to print its prompt template or conversation history
HijackingThe model's output is steered away from your instructionsIgnoring the template, or a fake completion that pre-fills a malicious answer
JailbreakingSafety rules are bypassedPersona switches, alternating languages, obfuscation or base64-encoded input
PoisoningHarmful content enters what the model learns from or readsGeneral term: tampered training data or documents in a retrieval source

The mapping of AWS's attacks to exam terms is our own grouping, not AWS's: Bedrock's Guardrails documentation, for example, describes persona takeover as a way of hijacking the model's goal. The poisoning row is a general definition rather than an item from AWS's attack list.

Defences work best in layers. Bedrock Guardrails content filters include a Prompt Attack category, and AWS notes that with InvokeModel the user input must be tagged as such for that filter to evaluate it. Guardrails can also be applied with the ApplyGuardrail API without invoking a model. AWS's prompt guidance recommends salted sequence tags, a session-specific string added to tags so attackers cannot spoof them. Validate outputs before they trigger any action, and never put secrets in a prompt template on the assumption that it stays hidden.

Key takeaways

  • A prompt combines instruction, context, examples and input; put the instruction last and state the output format.
  • Zero-shot has no examples, single-shot has one, few-shot has several and needs no training.
  • Chain-of-thought improves multi-step reasoning at the cost of more output tokens.
  • Prompt Management stores templates with variables, compares variants and deploys versions.
  • Plan for prompt injection with guardrails, tagged user input and output validation.

FAQ

Is few-shot prompting the same as fine-tuning?

No. Few-shot prompting puts examples in the prompt and changes nothing in the model. Fine-tuning changes the model's weights using training data. AWS calls few-shot prompting in-context learning.

When should I use chain-of-thought?

Use it for tasks with several reasoning steps, such as calculations or multi-condition rules. For simple classification it adds output tokens without much benefit.

What is a prompt variant in Bedrock Prompt Management?

An alternative configuration of the same prompt, which can differ in message, model or inference settings. You test variants against each other and keep the one that performs best.

Can a guardrail stop every prompt injection?

No single control stops every attack. Guardrails include a Prompt Attack filter, but AWS guidance pairs it with techniques such as salted tags, and you should still validate outputs and limit what the application can do.

Sources

Last checked 2026-11-22.

AI Guru Academy is an independent training provider and is not affiliated with or endorsed by Amazon Web Services. AWS service names are trademarks of Amazon.com, Inc. or its affiliates.

Next step: take the free diagnostic at /diagnostic, then see the full AIF-C01 course at /courses/aif-c01-exam-prep.

Prompt engineering techniques, with examples | AI Guru Academy