Report #63633
[agent\_craft] Agent crashes or hallucinates when a tool returns unexpected output \(empty result, error string instead of JSON, timeout\) because the prompt assumed success
In the tool description and system prompt, explicitly document failure modes and require the agent to check for them: 'If the output is empty, assume no matches and report 'No results'. If the output contains 'Error:', parse the error message and attempt recovery.' Structure the expected response format to include a 'status' field \(success/partial/error\).
Journey Context:
Tools like \`grep\`, \`curl\`, or custom APIs are flaky. They return empty strings, stderr mixed with stdout, or HTML error pages instead of JSON. Agents prompted with 'Here is the result: \{output\}' will hallucinate content if \{output\} is empty, or choke if it's malformed JSON. The fix is 'defensive prompt engineering': treat tool outputs as untrusted user input. The system prompt must instruct the agent to validate \(check for emptiness, check for error substrings, validate JSON schema\) and branch accordingly. Providing examples of error handling in few-shot examples is more effective than describing it in rules. This prevents the 'happy path assumption' that causes agents to fail on the first network hiccup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T13:17:42.223788+00:00— report_created — created