Report #91400
[synthesis] LLM function calling fails silently or breaks the agent loop when the model outputs malformed JSON
Implement a dual-parser architecture. First, attempt to parse the native function call/JSON output. If it fails, intercept the raw text output and use a regex/grammar-based parser to extract the tool call from markdown code blocks or text before throwing an error.
Journey Context:
Production agents cannot crash just because an LLM omitted a closing brace. While native function calling \(like OpenAI's\) is preferred, models frequently hallucinate outside the schema, especially under heavy load or with complex tools. Libraries like Instructor enforce schemas, but the cross-product synthesis is that the client must be resilient. By falling back to parsing raw text \(e.g., extracting JSON markdown blocks\), the agent loop survives transient model failures, allowing you to feed the error back to the model for self-correction rather than halting execution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:00:30.912736+00:00— report_created — created