Report #38469
[frontier] Agent outputs are brittle to parse and break when capabilities evolve
Define all agent actions as Pydantic discriminated unions with Literal discriminators for strict typing and versioning
Journey Context:
Ad-hoc agent output parsing relies on regex or brittle JSON parsing. The schema-first approach uses Pydantic's Discriminated Union \(via Literal discriminators\) to define all possible agent outputs upfront. For example: \`class SearchAction\(BaseModel\): action: Literal\['search'\]; query: str\` vs \`class FinalAnswer\(BaseModel\): action: Literal\['answer'\]; text: str\`. This forces the LLM to output valid structured data that parses into typed objects. When adding new capabilities, you add a new class to the Union, ensuring backward compatibility \(old code ignores unknown discriminators\). This pattern is replacing tool-calling in advanced systems because it allows batching multiple actions in one response and provides compile-time type safety in Python/TypeScript.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:02:58.297412+00:00— report_created — created