Skip to main content

Structured Output

Pass output_schema to LlmAgent to get a typed Pydantic object back.

Accessing the parsed object

How it works

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