str input and str output:
Structured Output
One of our favorite features is using Teams to generate structured data (i.e. a pydantic model). This is generally called “Structured Output”. 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. Structured output makes teams reliable for production systems that need consistent, predictable response formats instead of unstructured text. Let’s create a Stock Research Team to generate a structuredStockReport for us.
1
Structured Output example
structured_output_team.py
2
Run the example
Install librariesExport your keyRun the example
StockReport class, here’s how it looks:
Streaming Structured Output
Streaming can be used in combination withoutput_schema. This returns the structured output as a single RunContent event in the stream of events.
1
Streaming Structured Output example
streaming_structured_output_team.py
2
Run the example
Install librariesExport your keyRun the example
Structured Input
A team can be provided with structured input (i.e a pydantic model) by passing it in theTeam.run() or Team.print_response() as the input parameter.
1
Structured Input example
structured_input_team.py
2
Run the example
Install librariesExport your keyRun the example
Structured input is only available for the team leader. Structured input on member agents (when used in a Team) is not yet supported.
Validating the input
You can setinput_schema on the Team to validate the input. If you then pass the input as a dictionary, it will be automatically validated against the schema.
1
Validating the input example
validating_input_team.py
2
Run the example
Install librariesExport your keyRun the example
Typesafe Teams
For complete type safety with both input and output validation, Teams work similarly to Agents. You can combineinput_schema and output_schema to create fully typesafe teams that validate inputs and guarantee structured outputs.
For detailed examples and patterns of typesafe implementations, see the Agent Input and Output documentation, which demonstrates the same concepts that apply to Teams.
Using a Parser Model
You can use a different model to parse and structure the output from your primary model. This approach is particularly effective when the primary model is optimized for reasoning tasks, as such models may not consistently produce detailed structured responses.parser_model_prompt to your Parser Model to customize the model’s instructions.
Using an Output Model
You can use a different model to produce the run output of the team. This is useful when the primary model is optimized for image analysis, for example, but you want a different model to produce a structured output response.output_model_prompt to your Output Model to customize the model’s instructions.
Developer Resources
- View the Team schema
- View Cookbook