Session 2
Prompting & Structured Outputs
Today’s Agenda
Why Prompting Is Engineering
The Five Prompt Components
Zero-Shot vs Few-Shot
Chain-of-Thought Reasoning
Structured Outputs: Making AI Programmable
Enforcing JSON Output
The System Prompt
Interactive: Prompt Techniques
Interactive: System & Schema
Lab: Prompting in AI Studio (Core)
Classroom: Pause on each Interactive slide — cold-call a student or team before continuing.
Why Prompting Is Engineering
LLMs predict the next token. Your prompt shapes the probability distribution of the output.
Vague prompts → vague outputs
Specified format → parseable, programmable output
Repeatable rules → predictable results
The Five Prompt Components
Component Purpose
Role Set perspective & expertise level
Context Background information the model needs
Task Precise instruction of what to do
Format Structure of the output
Constraints Scope, length, or content limits
Bad output? Ask: which component is missing?
Zero-Shot vs Few-Shot
Zero-Shot
Classify as Positive, Negative, or Neutral:
"Late delivery, great product."
Works for simple, standard tasks
Few-Shot
"Broken on arrival." → Negative
"Exactly as described." → Positive
"Late delivery, great product." → ?
Better for complex or non-standard tasks
Chain-of-Thought Reasoning
"Think step by step before giving your final answer."
Forces the model to reason before concluding
Dramatically improves accuracy on logic & maths tasks
Exposes the model's reasoning for debugging
Interactive: Prompt Techniques (1/3)
Pick the strongest move for each case.
Prompt: Call on row 2 for Q1 — rewrite a weak prompt using Role + Format aloud.
Interactive: Prompt Techniques (2/3)
Pick the strongest move for each case.
Interactive: Prompt Techniques (3/3)
Pick the strongest move for each case.
Structured Outputs: Making AI Programmable
❌ Unstructured
Available in small (£12), medium (£18),
large (£24). Ships in 5 days.
Cannot reliably parse with code
✅ Structured JSON
{"sizes":[{"name":"small","price":12}...],
"shipping_days":5}
response.sizes[0].price always works
Enforcing JSON Output
You are a data extraction assistant.
Extract product details from the text below.
Respond ONLY with valid JSON matching this schema:
{
"sizes": [{"name": string, "price_gbp": number}],
"colours": [string],
"shipping_days": number
}
Do not include any text before or after the JSON.
Text: [product description here]
The System Prompt
Instructions that persist across all conversation turns — set persona, constraints, and format once.
SYSTEM: You are a concise technical assistant.
Always respond in JSON. Limit to 200 tokens unless asked to elaborate.
USER: What are the key factors in choosing a database?
Interactive: System & Schema (1/3)
True or false — shout, then tap.
Interactive: System & Schema (2/3)
True or false — shout, then tap.
Prompt: Call on Team C for Q2 — why freeform breaks parsing.
Interactive: System & Schema (3/3)
True or false — shout, then tap.
Lab 2.1: Basic Iteration
2.1 A: Zero-shot — summarise an article in 3 bullets
2.1 B: Add format constraints (≤20 words, plain English) — re-run
2.1 C: Force JSON: headline, summary[], sentiment — parse it
If output is wrong, ask which of the five components is missing.
Lab 2.2: Project Extraction
Identify the core data your project needs to process.
Write a robust prompt that extracts this information.
Define the JSON schema explicitly using the 5 components.
Test on 3 inputs .
Save the final prompt and sample output to prompts.md.
Lab 2.3: System Prompt
Draft a System Prompt for your specific course project.
Set the overarching persona.
Define absolute constraints.
Set formatting rules that must persist across interactions.
Add this System Prompt draft to your prompts.md file.
Session 2 Summary
Five components: Role, Context, Task, Format, Constraints
Few-shot and chain-of-thought improve complex output quality
JSON schemas make AI outputs programmable
System prompts establish persistent AI behaviour
Start your prompts.md library today
Next Session: The Personal Exocortex