Definition
"Write about photosynthesis" gets a generic essay. "You are a biology tutor. Explain photosynthesis to a 13-year-old in five short points, using an example from an Indian farm, and end with one quiz question" gets exactly what you need. The difference is prompting.
Prompting is the craft of writing inputs that get an LLM to produce useful, accurate output. Core techniques include giving clear, specific instructions with context; assigning a role; zero-shot prompting (just the task) and few-shot prompting (including worked examples); asking the model to reason step by step before answering, known as chain-of-thought; specifying the output format; separating instructions from data with delimiters such as tags; breaking complex tasks into a chain of smaller prompts; and supplying reference material to ground the answer.
In simple words
Prompting is like briefing a very capable new helper who knows a lot but nothing about your situation. The clearer your briefing, with the goal, the audience, examples and the format you want, the better the work you get back.
Overview
- A prompt is the input text that tells an LLM what to do.
- Good prompts state the task, context, audience, format and constraints clearly.
- System prompts set lasting instructions; user prompts give the specific request.
- Examples in the prompt (few-shot) show the model exactly what is wanted.
- Breaking big tasks into steps usually gives better results than one huge prompt.
- Prompts should be tested on many inputs, not just one.
Why it matters
The same model can be mediocre or excellent depending on the prompt. Good prompting is the cheapest way to improve quality, and it is the foundation for building reliable LLM applications.
Key terms
- System prompt
- Standing instructions that set the model's role, rules and style for a whole conversation.
- Zero-shot prompting
- Asking for a task with no examples.
- Few-shot prompting
- Including a few input-output examples to show exactly what you want.
- Chain-of-thought
- Asking the model to work through intermediate steps before the final answer.
- Delimiters
- Markers such as XML-style tags or triple quotes that separate instructions from data.
- Prompt chaining
- Splitting a task into steps, feeding each step's output into the next prompt.
Types
There are several types of prompting technique. Each suits a different kind of task.
1. Zero-shot prompting
Giving clear instructions without examples.
- How it works: The model relies on what it learned in training; precise wording, audience and format make a big difference.
- Example: "Explain photosynthesis to a 10-year-old in three short sentences."
- When to use it: Use it first for simple, common tasks. If the output is inconsistent or in the wrong format, move on to few-shot examples or a clearer structure.
2. Few-shot prompting
Including a few input-output examples before the real input.
- How it works: The examples show the pattern, labels and format to copy; GPT-3's 2020 paper showed this in-context learning.
- Example: Three example reviews labelled positive or negative, followed by the review to classify.
- When to use it: Use it for classification, extraction and any task with a specific style or format.
3. Role and context prompting
Telling the model who it is acting as and giving background information.
- How it works: A role ("You are a patient maths tutor") sets tone and level; context such as the audience and purpose guides content.
- Example: "You are a customer-support agent for an Indian railway app. Reply politely in Hinglish."
- When to use it: Use it to match tone and expertise to the audience; keep factual grounding separate from role.
4. Step-by-step and decomposition prompting
Asking the model to reason in steps, or splitting a task into a chain of prompts.
- How it works: Chain-of-thought prompting (Wei et al., 2022) improves multi-step reasoning; prompt chaining passes one step's output to the next.
- Example: First extract the facts from a report, then summarise them, then translate the summary.
- When to use it: Use it for maths, planning and long tasks; reasoning models do much of this internally.
5. Delimited, constrained and grounded prompting
Marking inputs clearly, limiting the output and supplying source material.
- How it works: Use delimiters such as triple quotes or XML-style tags around documents, state length and format limits, and ask the model to answer only from the provided text and say when it does not know.
- Example: "Using only the policy between <policy> tags, answer in under 50 words."
- When to use it: Use it to reduce hallucination and to keep untrusted input separate from instructions.
Explained in detail
The building blocks of a good prompt
| Element | Weak | Strong |
|---|---|---|
| Task | "Summarise this" | "Summarise this circular in 3 bullet points for students" |
| Context | (none) | "Students are 16 to 18 and read on phones" |
| Role | (none) | "You are a patient chemistry tutor" |
| Format | (unspecified) | "Return a table with columns Term and Meaning" |
| Examples | (none) | Two examples of the desired style |
| Constraints | (none) | "Use only the text below; say 'not stated' if unsure" |
Key techniques
Few-shot prompting, highlighted in the 2020 GPT-3 paper "Language Models are Few-Shot Learners", shows the model the pattern instead of describing it: two or three labelled examples of complaints and their categories often work better than a paragraph of rules. Chain-of-thought prompting, studied by Jason Wei and colleagues at Google in 2022, asks the model to reason step by step and improved accuracy on maths word problems substantially; many newer models now reason internally before answering, but asking them to show key steps still helps you check the logic. Delimiters prevent confusion between your instructions and the data being processed, and also reduce the risk that text inside a document hijacks the model, an attack called prompt injection. For complex jobs, chaining prompts, such as first extracting facts, then checking them, then writing, gives more control than one giant prompt.
- Tell the model what to do rather than only what not to do: "write in simple Hindi" works better than "don't use difficult words".
- Give the model permission to say "I don't know" or "not in the text"; this reduces invented answers.
- Iterate: change one thing at a time and compare outputs on the same test inputs.
Prompts for applications differ from prompts typed in a chat window. In an application, a system prompt is written once and reused for thousands of users, so it must handle many situations: it should state the assistant's purpose, its audience, what it must never do, how to respond when a question is outside its scope, the language to reply in and the format of answers. Variables such as the user's name or the retrieved document are inserted into a template at run time. Because one weak sentence in a system prompt affects every conversation, such prompts are reviewed, versioned and tested like code. Good application prompts are often long and detailed, but every sentence should earn its place, since each one costs tokens on every request.
How it works
- State the task, audience and goal clearly.
- Add context and, if helpful, a role.
- Show one to three examples of the output you want.
- Specify the format and length, and mark the data with delimiters.
- Ask for reasoning on hard problems, and test the prompt on several inputs.
In code
def build_prompt(task, context=None, role=None, examples=(), output_format=None, data=None, reason=False):
parts = []
if role:
parts.append(f"You are {role}.")
parts.append(task)
if context:
parts.append(f"Context: {context}")
for i, (inp, out) in enumerate(examples, 1):
parts.append(f"<example {i}>\nInput: {inp}\nOutput: {out}\n</example {i}>")
if data:
parts.append(f"<data>\n{data}\n</data>")
if reason:
parts.append("Think through the steps briefly, then give the final answer on the last line.")
if output_format:
parts.append(f"Format: {output_format}")
parts.append("If the answer is not in the data, reply 'not stated'.")
return "\n\n".join(parts)
zero_shot = build_prompt("Classify the complaint into electricity, water or sanitation.", data="Nal se ganda paani aa raha hai")
few_shot = build_prompt(
"Classify the complaint into electricity, water or sanitation.",
role="a municipal helpdesk assistant",
examples=[("Light nahi hai subah se", "electricity"), ("Kachra 3 din se nahi utha", "sanitation")],
data="Nal se ganda paani aa raha hai",
output_format="one word, lowercase",
)
for name, prompt in [("ZERO-SHOT", zero_shot), ("FEW-SHOT", few_shot)]:
print(f"===== {name} ({len(prompt.split())} words) =====\n{prompt}\n")Output
===== ZERO-SHOT (28 words) ===== Classify the complaint into electricity, water or sanitation. <data> Nal se ganda paani aa raha hai </data> If the answer is not in the data, reply 'not stated'. ===== FEW-SHOT (63 words) ===== You are a municipal helpdesk assistant. Classify the complaint into electricity, water or sanitation. <example 1> Input: Light nahi hai subah se Output: electricity </example 1> <example 2> Input: Kachra 3 din se nahi utha Output: sanitation </example 2> <data> Nal se ganda paani aa raha hai </data> Format: one word, lowercase If the answer is not in the data, reply 'not stated'.
Try it yourself
Prompting a lesson planner
A teacher in Bhopal uses an LLM to prepare a lesson on fractions.
Match the technique to its description
What does each technique do?
- Few-shot
- Chain-of-thought
- Delimiters
- Prompt chaining
- Role
Common mistakes
- Writing vague prompts without audience, format or length.
- Mixing data and instructions, so text in the data is followed as an instruction.
- Judging a prompt on one example instead of several.
Check yourself
Summary
- Good prompts state the task, audience, context, format and constraints clearly.
- Few-shot examples, chain-of-thought, delimiters and prompt chaining improve reliability.
- Let the model abstain, iterate one change at a time and test on several inputs.
Finished reading?
Sources: Anthropic: prompt engineering overview · Wei et al. (2022), Chain-of-Thought Prompting Elicits Reasoning in Large Language Models