Basic Concepts
Structured outputs
Working with freeform text from LLMs isn’t optimal when you know how you want the reply formatted.
Using structured outputs, you define a class, based on Pydantic’s BaseModel
, for the reply format you want and attach it to the LLM configuration. Replies from agent using that configuration will be in a matching JSON format.
In earlier examples, we created a classroom lesson plan and provided guidance in the agent’s system message to put the content in tags, like <title>
and <learning_objectives>
. Using structured outputs we can ensure that our lesson plans are formatted.
Add a format
function to the LessonPlan class in the example to convert the returned value into a string. Example here.