Types of Prompting (Zero-shot, Few-shot)
Types of prompting are the standard prompting techniques for instructing a large language model, distinguished mainly by how many examples the prompt contains and how the reasoning is structured. The most common types are zero-shot, one-shot, few-shot, chain of thought, role prompting and prompt chaining.
- Shot: A shot is one worked example, an input paired with its correct output, included inside the prompt.
- Zero-shot: The prompt contains instructions only, with no examples.
- Few-shot: The prompt contains several examples that demonstrate the expected format and categories.
- Reasoning techniques: Methods such as chain of thought prompting request intermediate steps before the final answer.
- Composition techniques: Methods such as prompt chaining divide a complex task into a sequence of smaller prompts.
For example, a zero-shot prompt asks the model to label a bug report as frontend, backend or infrastructure, while a few-shot prompt first shows three labelled reports.
Overview of Types of Prompting
| Type | How it works | Typical use |
|---|---|---|
| Zero-shot | Instructions only, no examples | Simple, well-defined tasks such as summarising a log |
| One-shot | One example before the input | Demonstrating an unusual output format |
| Few-shot | Several examples before the input | Classification with custom labels |
| Chain of thought | Requests step-by-step reasoning | Debugging and multi-step analysis |
| Role prompting | Assigns a persona or expertise | Code review with a consistent perspective |
| Prompt chaining | Passes one output into the next prompt | Multi-stage pipelines such as extract, then summarise |
Zero-shot Prompting
- Mechanism: It relies entirely on the model's pre-training and instruction tuning, with no demonstrations.
- Strength: It uses the fewest tokens and is the fastest prompt to write.
- Weakness: Output format and label choices can vary when the instructions are ambiguous.
Example: "Summarise the following error log in three bullet points."
One-shot Prompting
- Mechanism: It includes exactly one input and output pair before the real input.
- Strength: A single demonstration often fixes the output format without much additional length.
Example: one sample commit message, followed by a new diff that needs a commit message.
Few-shot Prompting
- Mechanism: It includes several examples, usually two to eight, that cover each expected category.
- Strength: It teaches custom labels and edge cases that are difficult to describe in instructions.
- Weakness: Examples increase cost, and an unbalanced set can bias the model towards one label.
Example: three labelled bug reports, followed by a new report and an empty "Component:" line.
Chain of Thought Prompting
- Mechanism: It asks the model to write intermediate reasoning steps before the final answer.
- Strength: It improves accuracy on multi-step tasks such as tracing the first failure in a log.
Example: "Identify which service failed first. Think step by step, then write the answer."
Role Prompting
- Mechanism: It assigns the model an identity, usually in the system prompt, as covered in system prompt vs user prompt.
- Strength: It sets the vocabulary, the priorities and the level of technical detail.
Example: "You are a senior security engineer reviewing Python pull requests."
Prompt Chaining
- Mechanism: It divides a task into stages, where each prompt receives the previous output as input.
- Strength: Each stage is simpler to evaluate and debug, and failures are isolated to one step.
- Weakness: Latency and cost increase with every additional model call.
Example: prompt one extracts fields from a bug report, and prompt two drafts a reply from those fields.
Example: Building a Few-Shot Prompt in Python
The program below generates a zero-shot and a few-shot prompt from the same instruction and compares their lengths.
# Build zero-shot and few-shot prompts that route bug reports to a component
INSTRUCTION = "Label each bug report with one component: frontend, backend or infrastructure."
examples = [
("Login button does nothing on Safari", "frontend"),
("POST /orders returns 500 when the cart is empty", "backend"),
("Nightly backup job fails with 'No space left on device'", "infrastructure"),
]
def build_prompt(instruction, shots, new_report):
lines = [instruction, ""]
for report, label in shots:
lines += [f"Bug report: {report}", f"Component: {label}", ""]
lines += [f"Bug report: {new_report}", "Component:"]
return "\n".join(lines)
new_report = "Search API times out after the Redis cache restarts"
zero_shot = build_prompt(INSTRUCTION, [], new_report)
few_shot = build_prompt(INSTRUCTION, examples, new_report)
print(few_shot)
print("---")
print("Zero-shot words:", len(zero_shot.split()))
print("Few-shot words:", len(few_shot.split()))Label each bug report with one component: frontend, backend or infrastructure.
Bug report: Login button does nothing on Safari
Component: frontend
Bug report: POST /orders returns 500 when the cart is empty
Component: backend
Bug report: Nightly backup job fails with 'No space left on device'
Component: infrastructure
Bug report: Search API times out after the Redis cache restarts
Component:
---
Zero-shot words: 23
Few-shot words: 60- One function, both types: Passing an empty example list produces a zero-shot prompt, so both types can be evaluated on the same test inputs.
- Consistent pattern: Every example uses identical "Bug report" and "Component" lines, and the prompt ends with an empty "Component:" line for the model to complete.
- Balanced coverage: Each label appears exactly once, which avoids biasing the model towards one category.
How to Choose Between Types of Prompting
- Start with zero-shot: Use it first for well-defined tasks, and measure the results on a small test set.
- Add examples for format or labels: Move to one-shot or few-shot prompting when outputs drift from the required format or the custom categories.
- Request reasoning for multi-step problems: Use chain of thought for debugging, calculations and log analysis, and remember that it increases output length.
- Split complex workflows: Use prompt chaining when one prompt performs several unrelated operations, or when intermediate outputs need validation.
- Consider alternatives: When hundreds of examples are needed, fine-tuning or retrieval with RAG is often more efficient than a longer prompt.
- Combine techniques: A production prompt frequently combines a role, several examples and structured output requirements.
Quick Quiz
Pick an answer to check yourself. Nothing is saved.
Question 1 / 3
1. What does the word "shot" mean in few-shot prompting?
Frequently Asked Questions
Zero-shot vs few-shot prompting: what is the difference?
Zero-shot prompting gives the model instructions only, while few-shot prompting adds several worked examples before the real input. Few-shot prompts are longer but usually follow custom formats and labels more consistently.
How many examples should a few-shot prompt contain?
Most few-shot prompts use between two and eight examples, with at least one for each expected label. The right number is found by testing, since each extra example adds tokens and cost.
Is chain of thought a type of few-shot prompting?
Chain of thought can be used in either form. A zero-shot version adds an instruction such as "think step by step", and a few-shot version includes examples that show the reasoning steps.
What is prompt chaining?
Prompt chaining splits a task into a sequence of prompts, where the output of one prompt becomes the input of the next. It makes each stage simpler to test, at the cost of more model calls.
Related Articles
- What is Prompt EngineeringLearn what prompt engineering is, how to design a prompt step by step, its key characteristics, uses and limits, with a Python code review prompt example.
- Chain of Thought PromptingLearn chain of thought prompting: how step-by-step reasoning improves LLM accuracy and how to parse the final answer, with a Python log triage example.
- System Prompt vs User PromptSystem prompt vs user prompt: who writes each, what belongs in each, how models prioritise them, with a comparison table and a Python code review example.
- Structured Output (JSON) from LLMsLearn how structured output gets JSON from an LLM: schemas, extraction prompts, constrained decoding and validation, with a Python bug report JSON check.
- Fine-Tuning LLMsLearn what fine-tuning LLM models means, how LoRA and full tuning work, when to use them, with a Python example that prepares chat-format training data.
- What is Context EngineeringLearn what context engineering is: selecting, ranking and fitting information into an LLM context window, with a Python token budget example and limits.