Structured outputs
You can force your Assistant to reply using structured outputs. This can be beneficial when you want the Assistant to return data in the form of json
.
Step-by-step guide
- Start by creating an LLM, a Tool and an Agent. Note that you usually only need to create the
llm
object once and re-use it for subsequent agents.
- Invoke your Agent with the
output_schema
parameter. This parameter should hold the desired schema.
By passing the output_schema
we make sure the Assistant returns a json
repsonse in our desired output schema.
You can also define the output schema for workflows.
-
If you want to define output schema for specific steps in a workflow, you can do so by passing the
output_schemas
to theinvoke
method.output_schemas
is a list of dictionaries where each dictionary contains thestep_id
and theoutput_schema
for that step. e.g.output_schemas=[{step_id: "step_id", output_schema: "schema"}, ...]
-
If you want to define output schema for only the final step, you can pass the
output_schema
to theinvoke
method.