Report #31302
[frontier] Agent graph makes routing errors due to free-text LLM decisions
Use Pydantic models with OpenAI \`response\_format\` or function calling to force structured routing decisions with explicit next-node targets
Journey Context:
Agents often use string parsing on LLM outputs to decide which node to visit next, leading to routing errors when the model outputs unexpected formatting. By defining a Pydantic \`Router\` model with literal types for allowed destinations \(e.g., \`next: Literal\["search", "calculate", "respond"\]\`\), and passing this as \`response\_format\`, the LLM is constrained to valid graph edges. This eliminates parsing code and makes the graph topology explicit in the type system. Alternatives like regex parsing are brittle; free-form 'reasoning' steps before structured output are safer but must output the structured decision last.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:55:37.245136+00:00— report_created — created