Skip to main content
Force an agent to return a typed Pydantic object instead of free-form text. Pass output_schema to LlmAgent.
The parsed object is available on event.data when it’s the final response:

How it works

  1. PydanticOutputParser.get_format_instructions() is appended to the system prompt
  2. When the LLM responds, PydanticOutputParser.parse() extracts and validates JSON
  3. If direct parsing fails, with_structured_output() is used as a fallback
  4. Works with streaming and multi-agent compositions