Report #22741
[frontier] Agents waste tokens and latency on generic parsing or regex extraction from unstructured LLM outputs
Enforce JSON schema validation at intermediate routing steps using OpenAI Structured Outputs or Instructor; use Pydantic models to define agent handoff protocols with typed 'action' discriminated unions
Journey Context:
Traditional agent implementations rely on 'ReAct' prompting with string parsing of 'Thought: ... Action: ...' patterns, which is brittle and requires few-shot examples. Modern approaches use constrained decoding \(like OpenAI's Structured Outputs or Gemini's JSON mode\) to guarantee valid JSON matching a Pydantic schema. For multi-agent routing, define a union type \(Discriminated Union\) where one field \(e.g., 'action'\) determines which agent handles the request. For example, \{'action': 'search', 'query': '...'\} vs \{'action': 'code', 'language': 'python'\}. This replaces fragile if/else logic on string content. The alternative is function calling \(tools\), but that requires the LLM to generate a tool call object; structured outputs are lighter for internal routing decisions. Be aware that structured outputs add latency compared to raw completions, but reduce retry loops. Use this for the 'supervisor' pattern where one LLM decides which specialized agent to invoke next.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:34:58.595230+00:00— report_created — created