Skip to main content
One of our favorite features is using Agents to generate structured data (i.e. a pydantic model). Use this feature to extract features, classify data, produce fake data etc. The best part is that they work with function calls, knowledge bases and all other features.

Example

Let’s create an Movie Agent to write a MovieScript for us.
movie_agent.py
Run the script to see the output.
The output is an object of the MovieScript class, here’s how it looks:

Using a Parser Model

You can use an additional model to parse and structure the output from your primary model. A parser_model can be employed to transform the raw response into structured output, replacing the default model for this specific task. This approach is particularly effective when the primary model is optimized for reasoning tasks, as such models may not consistently produce detailed structured responses.
You can also provide a custom parser_model_prompt to your Parser Model.

Streaming Structured Output

Streaming can be used in combination with response_model. This returns the structured output as a single event in the stream of events.
streaming_agent.py

Developer Resources