Report #1667
[architecture] Tool use reliability: why LLMs hallucinate tools and how to make tool calls trustworthy
Constrain tool selection with a strict schema and forced function calling, validate tool arguments with Pydantic before execution, and always handle three failure modes: invalid JSON, valid JSON but invalid args, and tool execution errors. Return structured errors to the model as observations rather than crashing the loop.
Journey Context:
LLMs are great at syntax and terrible at semantics: they will emit plausible-looking tool calls with wrong IDs or out-of-range parameters. Relying on raw string parsing invites failure. Use the provider's structured output / function-calling mode so the model is constrained to valid JSON. Then validate the parsed payload against the tool's input schema. Execute tools in a sandbox with timeouts and idempotency checks. When a tool fails, feed the error back into the conversation history as an observation so the model can self-correct. This closes the loop instead of terminating.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T06:47:48.479949+00:00— report_created — created