SESSION 5

Session 5 — Structured Outputs & Function Calling

Force the model into JSON, call tools, and orchestrate multi-tool flows.

3 hours20 exercises · 3 phases
What you'll be able to do by the end
  • ✓ Force any model into exact JSON shapes with strict JSON Schema
  • ✓ Define and invoke Python functions as tools from a chat conversation
  • ✓ Build a tool-calling loop that handles multi-step reasoning and parallel tools
  • ✓ Catch tool errors and refusals gracefully
  • ✓ Extract typed Pydantic objects from unstructured text with parse()
  • ✓ Know when to use response_format vs tools vs parse()

Prerequisites — tick these off first

The 3-phase arc

Phase 1 tightens the output shape. Phase 2 teaches the model to call your code. Phase 3 modernises it all with Pydantic. Do them in order the first time.

Phase 1
Schema
Phase 2
Tools
Phase 3
Pydantic

Exercises by phase

When you get stuck or finish