Structured agent output
Notebook· 02.05· 90–120 min· Lesson 23 of 129
The notebook opens in your lab, in a new tab. If your server is stopped, it starts first (a few seconds).
By the end you can
- Return a validated Pydantic object from an agent with
response_format, and read it fromresult["structured_response"]. - Explain the two strategies:
ToolStrategy(an extra "answer" tool) andProviderStrategy(the provider's JSON-schema mode), and what passing a bare schema chooses. - Pick the right strategy for Groq:
ToolStrategywhenever the agent has tools. - Handle validation errors and multiple answers with
handle_errors. - Offer alternative answer types with a
Union(for example, an answer or a refusal).
Before you start
Lesson 02.03 (create_agent). Lesson 01.05 (structured output from a model).
Python in this lesson
Python guideNew herematch / case
