Session 2 Slides: Prompting & Structured Outputs

--:-- --
↓ Scroll for more

Session 2

Prompting & Structured Outputs

AI Product Engineering

Block 1: Foundations & The Exocortex

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)

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

ComponentPurpose
RoleSet perspective & expertise level
ContextBackground information the model needs
TaskPrecise instruction of what to do
FormatStructure of the output
ConstraintsScope, 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.

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.

Interactive: System & Schema (3/3)

True or false — shout, then tap.

Lab 2.1: Basic Iteration

  1. 2.1 A: Zero-shot — summarise an article in 3 bullets
  2. 2.1 B: Add format constraints (≤20 words, plain English) — re-run
  3. 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

  1. Identify the core data your project needs to process.
  2. Write a robust prompt that extracts this information.
  3. Define the JSON schema explicitly using the 5 components.
  4. Test on 3 inputs.
  5. Save the final prompt and sample output to prompts.md.

Lab 2.3: System Prompt

  1. Draft a System Prompt for your specific course project.
  2. Set the overarching persona.
  3. Define absolute constraints.
  4. Set formatting rules that must persist across interactions.
  5. 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