Generative AI Intermediate: Prompting, Models and Grounding
Advanced Prompting Techniques
In this lesson you will
- Use few-shot examples and clear structure in prompts
- Ask for step-by-step reasoning and structured output
- Test and improve a prompt systematically
Introduction
Basic prompts give good answers to simple questions. When the task is complex, repeated or feeds into other tools, you need techniques that make the output reliable and predictable. These ideas work across most modern AI assistants.
Be specific and structured
Give the model what it needs: the task, the context, the audience, the constraints and the format. Use clear separators for different parts, so it does not mix instructions with data:
Task: Summarise the customer email below in 2 sentences.
Audience: a busy support manager.
Tone: neutral.
Email:
"""
Hi, I ordered a blue jacket on 3 March and it still has not arrived...
"""Triple quotes or tags such as angle-bracket labels mark where the data begins and ends. This also helps against prompt injection, where text inside the data tries to give the model new orders.
Few-shot prompting: show examples
Examples teach style and format faster than descriptions:
Classify each message as POSITIVE, NEGATIVE or NEUTRAL.
Message: "Great service, thanks!" -> POSITIVE
Message: "I waited an hour." -> NEGATIVE
Message: "The shop opens at nine." -> NEUTRAL
Message: "Delivery was quick but the box was damaged." ->Pick examples that are varied and correct, including tricky cases. Two to five good examples are usually enough.
Quick quiz
What is few-shot prompting?
Ask for reasoning
For maths, logic and multi-step problems, ask the model to work step by step before answering:
Solve this step by step, then give the final answer on its own line
starting with "Answer:".
A shop sells pens at 3 for 2.40. How much do 7 pens cost?Writing out the steps often improves accuracy. Check the reasoning, because a fluent explanation can still contain a mistake. For tasks with exact answers, verify with a calculator or code.
Ask for structured output
When another program will read the answer, request a strict format:
Extract the fields from the text. Reply with JSON only, using exactly these keys:
{"name": string, "date": string, "amount": number}Many AI services offer a built-in structured output mode that guarantees valid JSON. Still validate what comes back before you use it.
Other useful moves
- Give the model a role or perspective ("You are a careful proofreader") to set tone and focus.
- State what NOT to do, but lead with what to do.
- Break big tasks into steps, with one prompt per step, and feed the results forward.
- Let it say "I don't know". Add: "If the answer is not in the text, say so."
- Ask it to critique and improve its own draft, then you decide.
Treat prompts like code
A prompt that works on one example may fail on others. Test it:
- Collect 10 to 20 realistic inputs, including difficult ones.
- Run the prompt and mark each result good or bad.
- Change one thing at a time, and run again.
- Keep the best version and a note of why, ideally in version control.
Results can vary between runs and between models, so re-test when you change models.
Try it yourself
Pick a repeated task, such as classifying emails or summarising notes. Write a structured prompt with two examples and a strict output format. Test it on ten inputs and fix the worst failure.
Summary
- Structure prompts with clear parts, separators and constraints.
- Few-shot examples, step-by-step reasoning and strict output formats make results reliable.
- Test prompts on realistic inputs, change one thing at a time, and always verify important outputs.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading