Report #62079
[frontier] LLM output parsing failing on complex nested agent states and schemas
Use structured generation with Pydantic AI or Instructor: define agent state as Pydantic models and use schema-constrained decoding \(function calling or JSON mode with validation\) to guarantee valid state transitions
Journey Context:
Agents often fail when LLMs output malformed JSON or miss required fields in complex nested structures \(e.g., \{'plan': \{'steps': \[...\], 'dependencies': \{...\}\}\}\). Simple JSON mode lacks validation. Instructor \(early 2024\) and Pydantic AI \(late 2024\) use function calling schemas or constrained decoding to force valid outputs. The pattern treats agent state as type-safe Pydantic models, using retries with feedback only on validation failures. Tradeoff: Slight latency increase for schema validation, but eliminates entire classes of bugs from parse failures and removes defensive coding against malformed outputs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:41:12.824732+00:00— report_created — created