Guide · Access control
How to restrict and authorize AI agent tool calls at runtime
How do you make sure an AI agent only touches the data and tools it is authorized to use? Treat every tool call as a request that must be approved before it executes — not as something the model decides on its own.
Short answer
Give the agent a fixed role with a deny-by-default tool allowlist, check each tool call and its arguments at runtime before your code runs it, make tools act with the end user's own permissions, pin the tool definitions you reviewed, and stop the action whenever the check fails or cannot answer. Prompt instructions alone are not a boundary: an injected document can override them.
Step by step
1. Define the agent's role as a short tool list
Write down the job the agent does and the few tools that job needs. A support agent may need search_docs and create_ticket, never delete_user or send_payment. Everything not on the list is denied by default.
2. Check every planned tool call before it runs
Send the tool name and arguments to the guardrail before your code executes the tool. Vigil's tool allowlist rule returns allow, flag or block, and your code runs the tool only on allow.
3. Inspect the arguments, not just the tool name
An allowed tool can still be misused. Arguments are scanned for injected instructions, secrets and personal data, and outbound URLs are matched against the hosts you allow, so http_get cannot be pointed at an attacker's server.
4. Scope data access to the end user
Pass the signed-in user's identity to your own data layer and let it enforce row-level permissions. The agent should call tools with the user's rights, never with a shared admin key, so a prompt cannot widen what it sees.
5. Pin MCP tool definitions
Hash each MCP server's full tool definition when you review it. If the description or schema changes later, or a second server registers a tool with the same name, treat it as untrusted until reviewed again.
6. Fail closed and keep an audit trail
If the guardrail cannot be reached or returns an unknown verdict, stop the action. Every block is recorded with the tool, reason and agent, so you can show auditors exactly what was prevented.
What the check looks like in code
Using the downloadable Python client from the docs. The tool runs only after an explicit allow; any error stops it.
planned = [{"name": "http_get", "arguments": {"url": url}}]
validate_tool_arguments("http_get", planned[0]["arguments"]) # local, fails closed
verdict = await vigil.post_execution_check(prompt, draft_output, tool_calls=planned)
if verdict.get("verdict") != "allow":
raise SecurityViolationError(verdict.get("reason", "blocked"))
result = http_get(url) # runs only after an explicit allowFull, tested clients are in the Python SDK guide and the API docs.
Common mistakes
- Relying on the system prompt ("never call delete") as the only control.
- Giving the agent one powerful service key shared by all users.
- Checking the user's message but not documents or tool output the agent reads later.
- Letting the tool run when the security check times out.
Try it
Paste your agent's prompt or tool config into the free scanner (it runs in your browser), or compare approaches in runtime guardrails vs. WAFs.
Get a free API key →