Report #25091
[frontier] Agent output parsing fails due to markdown formatting, inconsistent JSON, or hallucinated tool arguments
Use native Structured Outputs with strict JSON Schema: define Pydantic models for each agent decision \(tool selection, arguments, state updates\) and pass them to the LLM's response\_format or structured\_output parameter with strict=True. Parse the response with model\_validate\_json; never use regex or manual string parsing on LLM output.
Journey Context:
Early agents relied on 'JSON mode' or worse, 'output JSON in a code block' which LLMs frequently corrupted with markdown backticks or explanatory text. Native Structured Outputs \(OpenAI, Anthropic, Gemini\) guarantee valid JSON matching the schema via constrained decoding. For agents, this is non-negotiable: tool arguments, routing decisions, and state updates must be machine-validated. In 2025, this replaces 'prompt engineering for format' with 'schema engineering for behavior'. Critical realization: the Pydantic Field descriptions serve as in-schema prompting, reducing the need for separate system instructions about output format.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:31:32.532593+00:00— report_created — created