Skip to content
LinkedInX

Tool Error Handling

Target audience: Those preventing an AI from spinning or silently continuing after a tool fails
Prerequisites: Basic understanding of What Is Tool Use

Tools fail. Without error handling, an AI either proceeds unaware of the failure or repeats the same call indefinitely.

Make Error Messages Actionable

To an AI, an error message is the input that determines the next move. Include not just the cause but the options available.

# No clue
Error: failed

# Actionable
Error: File 'config/settings.json' not found.
Check the path, or inspect the directory contents with list_files.

Avoid returning raw stack traces. They carry volume but rarely point to a next action.

Never Hide a Failure

The most dangerous design returns a normal-looking result after a failure.

DesignHow the AI reads itOutcome
Returns an empty array on failureInterprets it as “no matches”Proceeds on a wrong conclusion
Returns an error on failureRecognizes the failureRetries or escalates to a human
This table scrolls horizontally. Keyboard users can focus the table and use the left and right arrow keys.

“Nothing was found” and “retrieval failed” are different states. Return them distinguishably.

Match Retries to Error Type

Not every error resolves through retry.

Error typeExampleRetry
Transient faultNetwork drop, congestion, timeoutEffective, a few attempts with backoff
Bad inputInvalid parameter, wrong pathRetry after correcting the input
Insufficient permissionAccess deniedIneffective, escalate to a human
Target does not existDeleted resourceIneffective, revisit the plan
This table scrolls horizontally. Keyboard users can focus the table and use the left and right arrow keys.

Retrying an access denial changes nothing. Only transient faults reward a retry.

Cap and Escalate

Set a retry ceiling and hand off to a human once it is exceeded. Without a cap, retries combine with the self-correction loop and can repeat the same failure for a long time.

Summary

  • Error messages should carry both the failure and a clue about the next action
  • Returning a normal-looking result on failure lets the AI proceed on a wrong conclusion
  • Retries help only for transient faults, not for permission problems
  • Cap retries and escalate to a human beyond the limit
Quiz