Report #75045
[frontier] Agent loop breaks when model outputs malformed tool calls or wrong action types at intermediate steps
Enforce structured outputs with a discriminated union schema on every intermediate agent step, not just the final output. Define a schema where each step must be exactly one of: \{type: 'tool\_call', tool\_name, tool\_args\}, \{type: 'handoff', target\_agent, context\}, \{type: 'final\_response', content\}, or \{type: 'clarification\_needed', question\}. Use the model's constrained decoding to guarantee parseable output at every turn.
Journey Context:
The common mistake is using structured outputs only for the final response while letting intermediate reasoning steps be free-form. This causes agent loops to break in production when the model outputs malformed JSON in a tool call, outputs a tool call when it should output a final response, or gets stuck in an infinite loop because it has no way to signal 'I need user clarification'. The fix: constrain every step with a discriminated union schema. Both OpenAI \(structured outputs with response\_format\) and Anthropic \(tool\_use with required tools\) support this. Tradeoff: slightly reduced model flexibility—the model sometimes 'wants' to output something that doesn't fit the schema. But the reliability gain is enormous: production teams report eliminating 80%\+ of agent loop failures. Critical detail: always include a 'clarification\_needed' or 'error' variant in your schema so the model has an escape hatch when it's stuck, otherwise it will hallucinate into a tool\_call variant.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:33:23.938296+00:00— report_created — created