Validate AI Tool Results Before They Drive Another Action
By Numan ·
Check external tool output, provenance and size before an AI agent uses it in a later action.
Validate AI Tool Results Before They Drive Another Action
An agent may call one tool, read its result, then call another. That handoff is where untrusted data can become an instruction or an unsafe argument. OWASP's prevention cheat sheet (https://cheatsheetseries.owasp.org/cheatsheets/LLM_Prompt_Injection_Prevention_Cheat_Sheet.html) describes prompt-injection patterns in external content, and OpenAI's tool guidance (https://developers.openai.com/api/docs/guides/function-calling) shows that tool outputs return to the model for further steps.
Treat the result as data
Record which tool produced the result and which source supplied it. A web page can contain a sentence that looks like a system message; it is still page content. A repository issue can name a different account; it does not grant access to that account.
Validate fields in code
Before a result drives a write, check identifiers, destinations, amounts, and allowed status values against trusted service data. Limit length and type. If a field is absent or contradictory, stop or ask for clarification. Do not rely on a model to notice every mismatch in prose.
Keep the chain visible
Log the sequence of tool names, target IDs, and outcomes without secrets. If a final action is high-impact, show the human reviewer the source data that led to it and the exact proposed change. That makes a wrong inference easier to catch.
Add a chain test
Give the first tool a harmless response containing a forged instruction to call a write tool. The expected result is no unauthorized write, with a clear audit record. Test both the agent behavior and the backend permission check.
For permission design, see our least-privilege guide (https://ubits.tech/learning/p/least-privilege-ai-agent-tools).
Primary sources: OWASP prevention cheat sheet (https://cheatsheetseries.owasp.org/cheatsheets/LLM_Prompt_Injection_Prevention_Cheat_Sheet.html) · OpenAI function calling (https://developers.openai.com/api/docs/guides/function-calling).