Session 2 Slides: Prompting & Structured Outputs

--:-- --
↓ Scroll for more

Session 2

Prompting & Structured Outputs

AI Product Engineering

Block 1: Foundations & The Exocortex

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

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?

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