Practical Prompt Engineering
The same model gives weak or brilliant answers depending on the prompt — prompt engineering is the skill of asking well.
What you will learn
- Apply the role–task–context–format prompt pattern
- Use few-shot examples and prompt chaining
- Build a small reusable prompt template
Why prompting is a real skill
An LLM will answer almost anything — but the quality depends enormously on how you ask. Prompt engineering is the practical skill of writing instructions that get good, reliable answers. It is the most in-demand everyday AI skill right now, and the good news is it is mostly common sense made deliberate.
The core pattern: Role, Task, Context, Format
A strong prompt usually has four parts. Give the model a role, a clear task, the context it needs, and the format you want back (plus any constraints like length).
| Part | What it does | Example |
|---|---|---|
| Role | Sets the persona/expertise | “You are a friendly Python tutor.” |
| Task | The exact thing to do | “Explain what a list is.” |
| Context | Background it needs | “The reader is a total beginner.” |
| Format | Shape of the answer | “Answer in 3 short bullet points.” |
Before and after
Watch the jump from a vague prompt to a structured one:
# WEAK prompt
tell me about loops
# STRONG prompt (role + task + context + format + constraint)
You are a friendly Python tutor.
Task: explain what a "for" loop does.
Context: the reader has never coded before.
Format: 3 short bullet points, then one tiny code example.
Keep it under 80 words.Note: Output (sketch of the kind of answer each gets): - WEAK: a long, rambling, unfocused essay about loops in general. - STRONG: three tight beginner bullets plus a 3-line example, under 80 words — usable as-is. The model did not get smarter; the instructions did.
Few-shot prompting: show, don’t just tell
Few-shot prompting means giving the model a few worked examples of the input-and-output you want, before your real question. The model copies the pattern. It is the fastest way to lock in a format or style.
Classify the sentiment as positive or negative.
Review: "I loved it" Sentiment: positive
Review: "waste of money" Sentiment: negative
Review: "absolutely brilliant" Sentiment:Note: Output: positive The two examples taught the model both the task and the one-word output format, so it answered “positive” in exactly the right shape — no extra chatter.
Prompt chaining: break big jobs into steps
Prompt chaining means splitting a large task into a sequence of smaller prompts, where each step’s output feeds the next. It works far better than asking for everything at once.
- Prompt 1: “List 5 topics for a blog about healthy cooking.”
- Prompt 2: “Take topic 3 and write 5 section headings for it.”
- Prompt 3: “Write the first section from those headings in 100 words.”
Each step is small, easy to check, and easy to fix — much more reliable than “write me a whole blog post.”
A reusable prompt template
Keep a fill-in-the-blanks template so you never start from scratch:
ROLE: You are a {expert role}.
TASK: {the single thing you want done}.
CONTEXT: {who it is for, any facts the model needs}.
FORMAT: {bullets / table / JSON / word limit}.
IF UNSURE: say "I'm not sure" rather than guessing.Note: Output: (No output — this is a template to copy. The last line is a simple guard against hallucination from the previous lesson: invite the model to admit uncertainty.)
Tip: A quick checklist for any prompt: did I give it a role, a specific task, the context it needs, and the format I want? Add an example if the shape matters. Those five habits fix most weak answers.
Q. What is “few-shot prompting”?
✍️ Practice
- Rewrite “write me an email” into a full Role–Task–Context–Format prompt with a length limit.
- Design a 2-example few-shot prompt that turns a product name into a one-line slogan.
🏠 Homework
- Pick a real task you do (summarising, drafting, explaining) and write a reusable template for it using the five-part pattern.