Prompt Fundamentals
The same model can give a useless answer or a brilliant one. Very often, the only difference is the prompt. Prompt engineering is the skill of telling an LLM exactly what you want, clearly enough that it gets it right the first time.
In this session
- Why prompt engineering matters, with a before-and-after example
- The six elements of an effective prompt
- System, user and assistant roles
- Zero-shot and few-shot prompting
01Why prompts matter
An LLM only knows what you put in the prompt (plus what it learned in training). It cannot read your mind about the audience, length, format or rules. Compare these two prompts:
Like giving instructions to a tailor. “Make me a shirt” gets you a shirt. Your measurements, fabric, colour, collar style and the date you need it get you your shirt.
02Six elements of an effective prompt
A few practical tips:
- Be specific and positive: say what to do (“reply in 3 bullet points”) rather than only what not to do.
- Separate instructions from data with clear markers like triple quotes or XML-style tags, e.g.
<sms>…</sms>. This also reduces prompt-injection risk. - Give the model a way out: “If the answer is not in the text, say ‘not found’.” This reduces made-up answers.
- Iterate: test on 10–20 real inputs, look at failures, and refine. Prompting is an experiment, not a one-shot activity.
03System, user and assistant roles
Chat models receive a list of messages, each with a role:
- System messages are the best place for rules that must always hold (tone, safety, output format).
- User messages carry the request and any data.
- Assistant messages hold earlier replies. You can also write fake assistant turns as examples, which is one way to do few-shot prompting.
# pip install openai (works with any OpenAI-compatible API)
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY from the environment
messages = [
{"role": "system", "content": "You are a polite support assistant for an Indian bank. Answer in at most 2 sentences."},
{"role": "user", "content": "How long does a NEFT transfer take?"},
]
reply = client.chat.completions.create(model="gpt-4o-mini", messages=messages, temperature=0.2)
print(reply.choices[0].message.content)04Zero-shot and few-shot prompting
Zero-shot means you describe the task with no examples. Modern LLMs are good at this for common tasks. Few-shot means you include a few input → output examples. This helps a lot when the task has your own labels, a special format, or tricky edge cases.
| Zero-shot | Few-shot | |
|---|---|---|
| Examples in the prompt | None | Usually 2–8 |
| Best for | Common, well-defined tasks | Custom labels, strict formats, edge cases |
| Cost | Fewer tokens | More tokens per call |
| Watch out | Format may drift | Model may copy the examples too closely; keep them varied and balanced |
05Summary
- Clear prompts are the cheapest way to improve output quality.
- Use the six elements: role, task, context, format, constraints, examples.
- Put lasting rules in the system message; the request goes in the user message.
- Start zero-shot; add few-shot examples for custom labels and formats.
06Quick quiz
1. Where should “always reply in Hindi, max 50 words” go?
2. Few-shot prompting means…
3. Which line helps reduce made-up answers?
4. Why wrap user data in tags like <sms>…</sms>?
5. “Reply as JSON with label and reason” is which element?
07References
- Anthropic prompt engineering guide
- OpenAI prompt engineering guide
- Brown et al., Language Models are Few-Shot Learners (2020)