Report #36970
[agent\_craft] Agent crashes when tool returns malformed JSON or empty string
Wrap all tool outputs in try/parse blocks with graceful degradation: if JSON.parse fails, pass the raw string to the LLM with context 'Tool X returned unparseable output: \[raw\]'. Never let a parser exception propagate to stop the agent loop.
Journey Context:
Agents assume tools return valid structured data. In reality, APIs return 200 OK with HTML error pages, empty strings, or truncated JSON due to network issues. A strict parser throws, killing the agent session. The fix is defensive parsing: attempt schema validation, on failure, treat the output as text and inform the LLM. The LLM can often infer meaning from error HTML or partial JSON \(e.g., 'the tool returned a timeout page'\). This makes the agent robust to flaky tools. Alternatives like 'retry until valid' waste tokens on permanent errors \(404s\) or malformed data that won't fix itself.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:31:40.403415+00:00— report_created — created