Prompt engineering techniques: a practical guide to zero-shot, few-shot, chain-of-thought, and more
A hands-on guide to prompt engineering: the anatomy of a good prompt, the core techniques (zero-shot, few-shot, chain-of-thought, role prompting, delimiters, output formatting, decomposition, ReAct), the inference settings that shape output, prompt security risks, and what foundational AI exams like AIF-C01 test.
Prompt engineering is the cheapest, fastest way to change what a large language model does: you change the input, not the model. No training, no data pipeline, no GPU bill - just clearer instructions. It is the first rung of the customization ladder (see how AI models are trained for the full ladder), and it is heavily tested on every foundational AI and generative-AI exam, from the AWS AI Practitioner (AIF-C01) to the Azure and Google Cloud equivalents.
This guide is provider-neutral - the techniques work the same on any modern LLM. It covers the anatomy of a good prompt, the core techniques with when to use each, the inference settings that shape output, and the security risks you must know. Where an exam leans on something, there is an "On the exam" note. Treat it as a reference you scan by section.
What prompt engineering is (and is not)
What it is. Crafting and refining the text you give a model so it returns the output you want. It exploits what the model already learned during pre-training; you are steering, not teaching.
Why it matters. It is nearly free and instant. Before you reach for RAG or fine-tuning - which cost data, money, and time - you should exhaust prompting. Often a better prompt closes the whole gap.
What it is not. It does not change the model's weights. If the model simply lacks the knowledge (your private data) or a reliable behavior, prompting alone will not fix it - that is when you climb to RAG or fine-tuning. Do not confuse prompt engineering (writing better instructions) with prompt tuning (a training technique that learns "soft prompt" vectors); the exam treats prompt engineering as the no-retraining option.
The anatomy of a good prompt
Most strong prompts contain up to four parts:
- Instruction - the task: "Summarize," "Classify," "Translate," "Extract."
- Context - background the model needs: audience, tone, domain, constraints.
- Input data - the actual content to act on.
- Output indicator - the form of the answer: "Return JSON," "One sentence," "A bulleted list."
Principles that make each part work:
- Be specific and unambiguous. "Write a 3-sentence summary for a non-technical reader" beats "summarize this."
- Prefer positive instructions. Tell the model what to do, not just what to avoid; "Respond only with the category name" is clearer than a pile of "do not" rules (though negative constraints have their place - see below).
- Give constraints. Length, tone, reading level, format, what to exclude.
- Use delimiters. Wrap the input in clear separators - triple quotes, XML-style tags, or markdown headers - so the model knows where instructions end and data begins. This also reduces the risk of user-supplied text being read as instructions (see prompt injection).
- Specify the output contract. If another program will read the output, state the exact shape (valid JSON with these keys, no prose around it). Models do not respect structure unless you demand it.
The core techniques
Zero-shot prompting
What. Ask the model to do the task with no examples, relying purely on its pre-trained knowledge.
When. Simple, common tasks the model has clearly seen before (basic classification, straightforward summaries, general questions).
Risk. If the task is unusual or far from the model's training, zero-shot results can be unreliable - that is your cue to add examples.
On the exam. Zero-shot means no examples in the prompt. Its named risk is poor performance when the task is too far from what the model learned.
One-shot and few-shot prompting (in-context learning)
What. Include one (one-shot) or a few (few-shot) worked examples of input-and-desired-output in the prompt, so the model infers the pattern. This is also called in-context learning, because the model "learns" the task from the prompt's context without any parameter updates.
When. The task has a specific format, label set, or style you want matched consistently - for example, classifying messages into your own categories, or matching a particular tone.
How. Show 2 to 5 clean, representative examples that cover the range of cases, then give the new input. Consistent formatting across the examples matters more than quantity.
On the exam. Few-shot learning and in-context learning are the same idea: examples in the prompt, no retraining. It is the go-to answer for "make the model follow a specific pattern or label scheme without fine-tuning."
Chain-of-thought (CoT) prompting
What. Ask the model to reason step by step before giving the final answer, instead of jumping straight to it.
When. Multi-step problems: arithmetic, logic, planning, anything where intermediate reasoning helps.
How. Either provide examples that show the reasoning (few-shot CoT), or simply append a trigger like Let's think step by step to elicit reasoning with no examples (zero-shot CoT).
On the exam. Chain-of-thought is the named technique for improving performance on complex, multi-step reasoning.
Self-consistency
What. Run chain-of-thought several times (with some randomness), then take the answer that comes up most often across the runs.
When. High-stakes reasoning where a single chain might slip; sampling several and voting improves reliability.
Role (persona) and system prompting
What. Tell the model who to be - "You are a senior tax advisor," "You are a terse code reviewer." In chat models this often lives in a separate system prompt that sets persistent behavior.
When. To fix tone, expertise level, or perspective across a whole conversation.
How. State the role, the audience, and the constraints up front. Keep the system prompt stable; vary the user prompt.
Delimiters and structure
What. Use explicit markers to separate the parts of your prompt (instructions vs data vs examples).
Why. It improves the model's adherence to each section and, importantly, helps stop untrusted input from being interpreted as instructions.
Output formatting
What. Specify the exact output shape and, ideally, ask the model to wrap the answer in tags or return strict JSON.
Why. Essential when the output feeds another program or model. An explicit output contract turns flaky parsing into reliable pipelines.
Prompt templates
What. Reusable, parameterized prompt structures with placeholders you fill at runtime.
Why. Consistency and maintainability - your app produces the same well-tested prompt every time, varying only the input. Managed platforms often provide prompt-template and prompt-management features for exactly this.
Task decomposition and prompt chaining
What. Break a complex job into smaller prompts and feed each step's output into the next.
When. A task is too big or multi-stage for one prompt (extract, then analyze, then draft). Chaining is more reliable than asking for everything at once, and each step is easier to test.
ReAct (reason + act)
What. A pattern where the model alternates reasoning with actions - calling tools, searching, or querying data - then observing the result and continuing. It is the prompting idea behind agents.
When. The model needs external information or must take steps in the world, not just answer from memory. (This connects prompt engineering to agent frameworks.)
Negative prompting
What. Explicitly state what to exclude or avoid - "Do not include personal opinions," "Exclude any code," or, for image models, listing elements you do not want.
When. To rule out known failure modes. Use it as a targeted supplement to positive instructions, not as the whole prompt.
The inference settings that shape output
Prompt text is only half the story. These generation parameters change the output without changing a word of your prompt:
- Temperature - randomness. Low (near 0) gives deterministic, repeatable, focused answers; high gives creative, varied ones.
- Top-p (nucleus sampling) and top-k - limit the pool of candidate next tokens the model may sample from, another lever on diversity.
- Max tokens - caps the length of the response.
- Stop sequences - strings that tell the model to stop generating.
On the exam. "Make answers more consistent or repeatable" means lower the temperature. Know that temperature and top-p/top-k control randomness and diversity, and are set at inference time, not baked into the prompt text.
Where prompting fits vs RAG and fine-tuning
Prompt engineering is the first thing to try, but it has limits. The customization ladder, cheapest first:
- Prompt engineering - shape the instructions. No new knowledge, no retraining.
- RAG (retrieval-augmented generation) - inject your own current data into the prompt at query time. Use it when the model needs facts it was never trained on, or when knowledge changes often.
- Fine-tuning - retrain on labeled examples to bake in a behavior or style. Use it when prompting and RAG still are not consistent enough.
On the exam. If a scenario needs private or up-to-date facts, prompting alone will not do - that is RAG. If it needs a reliably repeated behavior or domain style, that is fine-tuning. Prompting is the answer when the model can already do the task and just needs clearer steering.
Prompt security and responsible use
Prompts are an attack surface. Foundational exams test these under responsible-AI and security:
- Prompt injection - an attacker hides instructions in user-supplied input (or in a document the model reads) to override your system prompt and hijack the model's behavior or downstream actions.
- Jailbreaking - crafted prompts that bypass the model's safety guardrails to produce restricted or harmful output.
- Prompt leaking - coaxing the model into revealing its own hidden system prompt or confidential context.
- Adversarial prompting in general - the umbrella term for these manipulation techniques.
Mitigations you should know:
- Separate and clearly delimit trusted instructions from untrusted user input; never concatenate them blindly.
- Validate and sanitize inputs; constrain what the model is allowed to output and do.
- Apply guardrails / content filters and PII redaction on both input and output.
- Give the model and any connected tools least-privilege access, so a successful injection cannot do much.
- Keep a human in the loop for high-stakes actions.
Prompting also helps with hallucination: ground the model in retrieved facts (RAG), ask it to cite sources, and explicitly permit "I don't know" so it stops inventing answers. Lowering the temperature and adding grounding reduces confident nonsense.
Best-practice checklist
- Start simple; add complexity (examples, reasoning, chaining) only when the simple prompt fails.
- Be specific: state the task, audience, constraints, and exact output format.
- Use delimiters to separate instructions from data.
- Add examples (few-shot) when you need a specific pattern; add
Let's think step by stepwhen you need reasoning. - Iterate and test on real inputs; small wording changes matter.
- Lower the temperature for consistency; raise it for creativity.
- Treat user input as untrusted; delimit it, validate it, and guard the output.
The 30-second decision guide
- Simple, familiar task -> zero-shot
- Need a specific format or label scheme -> few-shot (in-context learning)
- Multi-step reasoning -> chain-of-thought (add
Let's think step by step) - Need higher reliability on hard reasoning -> self-consistency (sample and vote)
- Fix tone or expertise across a chat -> role / system prompt
- Output feeds another program -> specify a strict output format (JSON, tags)
- Task too big for one prompt -> decompose and chain
- Model needs tools or live data -> ReAct / agents
- Need private or current facts -> RAG, not prompting
- Need a consistently repeated behavior -> fine-tuning, not prompting
- Make output deterministic -> lower the temperature
Related certifications
Prompt engineering is core to every generative-AI exam - this guide appears under Related Study Guides on each of their hubs:
- AWS Certified AI Practitioner (AIF-C01) - tests prompt techniques, in-context learning, and inference parameters directly.
- AWS Certified Generative AI Developer Professional (AIP-C01) - goes deeper on building with prompts, RAG, and agents.
- Microsoft Azure AI Fundamentals (AI-900 / AI-901) - generative AI and prompting basics.
- Google Cloud Generative AI Leader - prompt design and foundation-model use.
- NVIDIA-Certified Associate: Generative AI and LLMs (NCA-GENL) - LLM prompting and adaptation.
- Claude Certified Architect - Foundations (CCA-F) - prompting Claude effectively.
- IBM watsonx Generative AI Engineer Associate - generative AI foundations.
How to study this
For an exam, practice matching a scenario to a technique, and know the boundaries that trip people up: zero-shot vs few-shot, chain-of-thought as the reasoning tool, temperature as the consistency lever, and - the big one - prompting vs RAG vs fine-tuning (steering vs adding facts vs changing behavior). For real work, keep prompts specific, delimited, and tested, and treat every user-supplied string as untrusted. Run practice questions with the 30-second decision guide open, and when you miss one, reread that technique here until the line is sharp.
Source: the AWS Certified AI Practitioner (AIF-C01) exam guide and question domains, and standard prompt-engineering references, as of September 2026.