Paper · 2026-09-29 · cs.CR, cs.AI
ToolFence: Fine-Grained Authorization for Secure Tool-Using LLM Agents
ToolFence compiles a typed, provenance-aware authorization blueprint before the agent reads external content, enforces it with a deterministic monitor, and asks a judge to grant capability shapes instead of judging each call. On AgentDojo with Qwen3-max, overall ASR falls from 21.20% to 0.20% for a 3.80-point clean-utility drop (author-reported).
Prompt injectionTool useLLM agentprompt-injectionagent-securityauthorizationtool-use
AI-compiled by claude-haiku-5-5 on 2026-11-21, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
Many defences for AI agents try to spot a malicious instruction hidden in a web page or an email. ToolFence works one level up and asks which actions the agent may take at all. Before the agent reads any outside content, a policy model writes down the allowed tools and where each sensitive value, such as a payment recipient or an amount, has to come from. A payment's recipient, for example, must come from the bill file the user named, and its amount from the user's own request.
A simple checker enforces this rule on every tool call without calling a model. When the agent reaches for something the plan did not cover, a judge model can add that kind of step to the plan, and the checker then reuses the rule for later calls. The idea is that a hijacked agent cannot send money to an attacker's account just because it still uses the right tool.
The paper reports near-zero attack success on its test suite, with a small loss in task completion and some extra time per run. These figures are the authors' own.
TL;DR
Relevant if you build tool-using agents and need a prompt-injection defence that keeps most calls deterministic. ToolFence compiles a blueprint of allowed tools and value provenance, checks calls with a non-LLM monitor, and grants new capability shapes through a judge that is cached across sessions. On AgentDojo with Qwen3-max, overall ASR falls from 21.20% to 0.20%, clean utility from 42.70% to 38.90%, at 1.63× runtime against 12.95× for CaMeL (author-reported) § Abstract §4.2 §4.5. The code is not released, and several mechanisms are under-specified (see Pitfalls).
Problem
Indirect prompt injection makes an agent act on instructions found in retrieved content, and the paper argues that defending the first prompt is not enough §1. Three gaps motivate the work §1:
- Within-tool attacks. The attacker keeps the intended tool and changes an authority-sensitive argument (recipient, amount, URL, destination). Input filters, structure-aware methods and consensus defences examine content or aggregated outputs and do not authorise the effect §1 §2.
- Strong isolation is slow. CaMeL gives strong control- and data-flow isolation but needs a custom pipeline and extra computation, which raises latency and cost §1.
- Static tool filtering starves the agent. A fixed allowlist cannot foresee every legitimate step, so benign calls outside the plan are denied §1.
The security unit the paper proposes is the capability: a tool, its effect class and provenance constraints on its sensitive parameters. The shape can be reused, while concrete values are re-checked on every call §1 §3.2.
Method
ToolFence is an inference-time defence that separates capability authorisation from action execution §3. It has four parts §1 fig. 1:
- A typed authorisation blueprint compiled before any external content is read §3.2.
- A deterministic monitor that matches each proposed call against the blueprint without an LLM §3.3.
- A runtime capability grant, where a judge grants a new capability shape when a call misses the blueprint §3.4.
- A cross-session cache of granted shapes, stored without argument values §3.5.
Threat model §3.1. The attacker can place arbitrary text in any channel the agent reads, such as fetched documents, tool results or web pages. The base model is not assumed to resist injection. The design needs only a trusted controller that mediates every proposed action before it runs §3.1.
Blueprint §3.2. A policy architect, an isolated LLM call, sees just the authenticated query and the tool schemas that the controller owns, so it is never shown untrusted content. Its output is a pair (manifest, capabilities). The manifest gives each tool one effect label from a fixed set that covers reading, local computation, messaging, payments, external writes, deletion and others. It also marks each parameter as authority-sensitive or not. Each capability is a tuple eq. 1:
c = (\text{tool},\; e,\; \{p_j \mapsto \beta_j\},\; \kappa,\; r) eq. 1
Here e is the effect, β_j is a binding for parameter p_j, κ is a call budget and r is a reusability flag §3.2.
Each binding states where the value must come from §3.2:
- literal: the value appears in the user's request q;
- derived: taken from what a named source tool s returned;
- template: fits a pattern anchored in the user's request and in a source tool's output;
- free: not authority-sensitive, so the agent may choose it.
The blueprint stores provenance constraints rather than concrete values. The paper's example is a send_money(recipient, amount) tool, where the recipient is derived from read_file("bill.txt") and the amount is literal from the user query eq. 2 §3.2.
\texttt{send\_money}: \quad \texttt{recipient} \leftarrow \texttt{read\_file("bill.txt")}, \quad \texttt{amount} \leftarrow q eq. 2
Deterministic monitor §3.3. For each proposed call, the monitor checks three things, without an LLM:
- Capability match. A capability for the same tool declares every argument in the call.
- Binding compliance. Each value satisfies its binding. A literal has to be found in the request q. A derived value has to be found in what a declared source tool returned earlier in the run. A template value has to fit its pattern and its source tools have to have run.
- Budget. The number of committed calls to the capability is below κ, or the capability is a reusable read (r true).
If all three hold, the call goes on the fast path and is dispatched at once.
Read auto-allow §3.3. A read-only call whose arguments all have user provenance is auto-allowed, because it cannot introduce a new access target. A read whose arguments come from tool output or from the model goes to the judge. The paper says that trusting all reads gave 60% ASR in a pilot, because of an AgentDojo Slack injection that is completed by fetching an attacker-controlled URL §3.3.
Runtime capability grant §3.4. When a call misses the blueprint, the controller labels each argument's provenance as user, tool:
For a well-formed proposal, the judge receives only a shape: the tool, its effect, and for each parameter a provenance constraint and a sensitivity flag. No concrete values are included. It answers grant or deny. The judge should approve only when the capability serves the request and each sensitive parameter is tied either to the user's own text or to a source the request named §3.4 app. B.2. After a grant, ĉ is appended to the running capability set, its budget is registered, and the original call passes the fast-path check again before dispatch. After a denial, a single per-call judge verdict decides the call §3.4 alg. 1.
Cross-session cache §3.5. A process-level cache G is keyed by a value-free signature of each capability eq. 3:
\mathrm{sig}(c) = \bigl(\text{tool},\; e,\; \{p_j \mapsto (\beta_j, \text{source\_tools}_j)\}\bigr) eq. 3
The cache keeps only binding types and source-tool names. It never stores values, evidence text or earlier outputs. In a new session, a cached capability still checks each concrete argument against what the declared source returned in that same session §3.5 app. A.1.
Main loop alg. 1 app. A.3. The pipeline below follows Algorithm 1. The paper's Algorithm 1 is printed in Appendix A.3; it is the first algorithm in the paper.
# ToolFence per-call handling [alg. 1] [§3.3] [§3.4] [§3.5]
# Input: action = (tool, arguments); capabilities; grant_cache
# Output: dispatched result or denial message
def handle_call(action, capabilities, grant_cache):
# Fast path: deterministic match of tool, bindings and budget [§3.3]
if monitor_allows(action, capabilities):
return dispatch(action)
# Provenance per argument: "user", "tool:<name>" or "model" [§3.4]
provenance = label_provenance(action, user_request, observations)
# Read auto-allow: every argument has user provenance [§3.3]
if is_read(action) and all_user(provenance):
return dispatch(action)
# Value-free shape; None if an authority-sensitive argument is
# model-generated, so the judge is never asked [§3.4] [app. A.2]
shape = build_grant_shape(action, provenance)
if shape is not None and signature(shape) in grant_cache:
# Cache hit: no judge call; concrete values are still checked [§3.5]
capabilities.append(shape)
return dispatch(action)
if shape is not None and grant_judge(shape) == "grant":
# A parse failure counts as deny [app. A.2 eq. 7]
capabilities.append(shape)
grant_cache.add(signature(shape))
return dispatch(action)
# Fallback: one per-call judge verdict [§3.4] [alg. 1]
if call_judge(action) == "deny":
return denial_message(action)
return dispatch(action)Monitor check, as described in §3.3:
# Deterministic monitor: no LLM call [§3.3]
# Input: action = (tool, arguments); capabilities (list)
# Output: True if the fast path authorises the call
def monitor_allows(action, capabilities):
for cap in capabilities:
# Capability match: same tool, declares every argument [§3.3]
if cap.tool != action.tool:
continue
if not set(action.arguments) <= set(cap.bindings):
continue
# Binding compliance: each value meets its declared provenance
# (literal in q; derived from an executed source's output) [§3.3]
ok = all(
binding_holds(value, cap.bindings[name], executed_sources)
for name, value in action.arguments.items()
)
if not ok:
continue
# Budget: committed calls below kappa, or a reusable read [§3.3]
if cap.committed_calls < cap.budget or cap.reusable:
return True
return FalseHyperparameters
Only the values below are stated in the paper. Everything else the implementer needs is marked "not stated".
| Name | Value | Where | Notes |
|---|---|---|---|
| Benchmark | AgentDojo, four suites (Workspace, Slack, Travel, Banking) | §4.1 | Official environment-state verifier used for all metrics §4.1 |
| Parameter-aware split | 629 pairs: 524 cross-tool, 85 within-tool, 20 ambiguous | §4.1 tab. 3 app. C.1 | 609 non-ambiguous pairs are scored (see Pitfalls) |
| Attack strategies | 6: Direct, Ignore Previous, Important Instructions, InjecAgent, System Message, Tool Knowledge | §4.1 | Main-table ASRs are averages over these six |
| Models | Qwen3-max; GPT-4o (gpt-4o-2024-08-06); Mistral-Small-3.1-24B-Instruct-2503 (Mistral in appendix) | §4.1 app. C.3 | Same backbone for all methods within a comparison block §4.1 |
| Policy architect model | not stated | §3.2 | An "isolated LLM call"; the paper does not name the model, temperature or token limit |
| Judge model | not stated | §3.4 app. B | "LLM judge"; model, temperature and token limit not named |
| Judge output | one JSON object; reason at most 25 words; unparseable output is deny | app. B.1 app. B.2 app. A.2 eq. 7 | Fail-closed on the grant judge; see Pitfalls for the per-call fallback |
| Capability budget κ | not stated per capability | §3.2 §3.3 | The monitor checks it; no default value is given |
| Reusable flag r | not stated default | §3.2 | Set to true for reusable read capabilities §3.3 |
| SecInfer candidate paths K | 5 | §4.1 app. C.2.4 | Baseline setting |
| SecInfer temperature | 0.7 | §4.1 app. C.2.4 | Baseline setting |
| Seeds and intervals | fixed seeds; means with 95% bootstrap confidence intervals; five random seeds in the figure caption | §4.1 fig. 2 | Number of seeds per table not stated |
| Tool-loop limit, max output length, retry policy | not stated as values | §4.1 | Said to be matched across methods; the values are not given |
| Runtime sample | 50 clean tasks and 200 attacked pairs | §4.5 | Used for the runtime figure |
| Mistral serving | vLLM v0.29.0 | app. C.2.1 | Tool-filter baseline was changed for this setup |
Results
Author-reported. Setup: AgentDojo, six attack strategies, Qwen3-max and GPT-4o, official verifier §4.1. Overall ASR is the average over the 609 user-attack pairs tab. 1.
Table 1: main results tab. 1
| Defence | Qwen3-max clean utility | Qwen3-max utility under attack | Qwen3-max overall ASR | Qwen3-max cross-tool ASR | Qwen3-max within-tool ASR | GPT-4o clean utility | GPT-4o utility under attack | GPT-4o overall ASR | GPT-4o cross-tool ASR | GPT-4o within-tool ASR |
|---|---|---|---|---|---|---|---|---|---|---|
| No Defense | 42.70 | 31.85 | 21.20 | 20.08 | 28.11 | 84.20 | 51.00 | 38.01 | 36.80 | 45.50 |
| Repeat Prompt | 37.18 | 29.45 | 10.95 | 10.23 | 15.42 | 81.00 | 66.10 | 17.91 | 16.70 | 25.40 |
| Spotlighting | 39.33 | 32.83 | 18.56 | 17.54 | 24.90 | 82.50 | 55.40 | 22.83 | 21.50 | 31.00 |
| Tool Filter | 30.44 | 31.88 | 1.67 | 0.45 | 9.18 | 78.60 | 60.50 | 6.76 | 4.90 | 18.20 |
| SecInfer | 39.45 | 34.80 | 14.31 | 13.30 | 20.50 | 86.50 | 72.40 | 14.51 | 13.00 | 23.80 |
| PromptArmor | 36.40 | 28.75 | 7.09 | 6.20 | 12.60 | 77.80 | 58.90 | 9.61 | 8.70 | 15.20 |
| CaMeL | 32.67 | 25.82 | 0.42 | 0.20 | 1.80 | 70.50 | 47.80 | 1.28 | 1.00 | 3.00 |
| ToolFence | 38.90 | 32.45 | 0.20 | 0.10 | 0.80 | 82.70 | 73.80 | 0.90 | 0.70 | 2.10 |
Headline numbers for ToolFence §4.2 §4.5:
- Qwen3-max: overall ASR 21.20 → 0.20; clean utility 42.70 → 38.90 (−3.80 points); runtime 1.63× (10.3 s per sample) §4.5.
- GPT-4o: overall ASR 38.01 → 0.90; clean utility 84.20 → 82.70; runtime 3.79× (17.1 s per sample) §4.5. The no-defense seconds are not given in the active text.
- CaMeL: 48.0 s and 81.7 s per sample, at 10.67× and 12.95× §4.5. The text does not say which model each figure belongs to.
Table 2: ablation on Qwen3-max tab. 2
| Configuration | Utility under attack | ASR | Judge calls per task | Runtime |
|---|---|---|---|---|
| Per-call runtime judge (reference) | 31.20 | 4.35 | 6.35 | 3.20× |
| Blueprint + deterministic monitor | 25.60 | 0.45 | 0.00 | 1.45× |
| + dynamic runtime capability grant | 30.40 | 0.18 | 1.84 | 2.78× |
| + cross-session capability cache | 31.80 | 0.18 | 1.05 | 1.96× |
| Full ToolFence (+ read auto-allow) | 32.45 | 0.20 | 0.82 | 1.90× |
The cache lowers judge calls from 1.84 to 1.05 per task, a 42.9% reduction §4.3. The paper's "43%" figure matches this comparison §3.5.
Table 4: Mistral-Small-3.1-24B tab. 4 (appendix, app. C.3)
| Defence | Clean utility | Utility under attack | Overall ASR | Cross-tool ASR | Within-tool ASR |
|---|---|---|---|---|---|
| No Defense | 50.39 | 32.47 | 13.98 | 12.97 | 20.19 |
| Repeat Prompt | 57.61 | 45.70 | 11.01 | 10.47 | 14.35 |
| Spotlighting | 59.30 | 43.48 | 19.88 | 18.86 | 26.21 |
| Tool Filter | 37.93 | 29.98 | 1.41 | 0.39 | 7.69 |
| SecInfer | 60.20 | 50.80 | 10.26 | 9.20 | 16.80 |
| PromptArmor | 50.10 | 40.20 | 6.12 | 5.20 | 11.80 |
| CaMeL | 34.50 | 27.80 | 0.42 | 0.20 | 1.80 |
| ToolFence | 55.80 | 52.30 | 0.13 | 0.05 | 0.60 |
Parameter-aware split tab. 3 app. C.1
| Suite | Pairs | Escalation (cross-tool) | Within-tool | Ambiguous |
|---|---|---|---|---|
| Workspace | 240 | 222 | 18 | 0 |
| Slack | 105 | 86 | 19 | 0 |
| Travel | 140 | 114 | 6 | 20 |
| Banking | 144 | 102 | 42 | 0 |
| Total | 629 | 524 | 85 | 20 |
Figures, described in words (no images are reproduced here):
- fig. 1: the ToolFence pipeline, showing the blueprint, the deterministic monitor, the capability grant and the cross-session cache.
- fig. 2: ASR by the six attack strategies on Qwen3-max, cross-tool and within-tool separately, with error bars over five random seeds. Tool Filter stays higher on within-tool than cross-tool ASR; ToolFence stays low on both.
- fig. 3: overall ASR per suite on Qwen3-max; ToolFence is consistently low across the four suites, and Banking and Slack are the harder suites §4.2.
- fig. 4: mean end-to-end runtime per sample on GPT-4o and Qwen3-max, for each defence §4.5.
Paper vs code
No official code.
Checked: the paper has no code or project link in the abstract or body (LaTeX source searched for code, GitHub and availability terms). GitHub repository searches for "ToolFence" and "toolfence agent", and a user search on the author names, returned no repository owned by the authors. Several unrelated third-party repositories carry the name ToolFence; none were used. The Ethics Statement says the authors "will release evaluation artifacts" § Ethics Statement. This is a future promise, not a released repository.
Consequence: every mechanism below is taken from the paper text alone, and none of it has been checked against an implementation.
Pitfalls
- Models behind the architect and the judge are not named. The paper says the architect is an isolated LLM call §3.2 and the judge is an LLM §3.4, but gives no model, temperature or token limit for either. It also does not say whether they share the agent's backbone. For CaMeL, the authors state they used one backbone for both of its LLMs app. C.2.5. An implementer should expect the grant and fallback decisions to depend on this choice.
- A grant denial is not final. After a grant denial, one per-call judge verdict decides the call, and the call is dispatched if that verdict allows it §3.4 alg. 1. The fail-closed statement in Appendix A.2 says a call with no capability and no grant "is not dispatched" app. A.2 eq. 5. That does not match Algorithm 1. Only the grant judge's parse failure is fail-closed in the text (eq. 7), not the per-call judge's.
- How "occurs in q" is tested is not stated. Provenance labels and binding checks depend on whether a value appears verbatim in the request or in a tool output §3.2 §3.4. The paper does not say how values are compared: exact or normalised text, case, whitespace, number formatting, or partial matches. Short values, such as numbers, may appear in many sources, and the paper does not say how it handles this.
- Cache semantics are only partly specified. The cache is process-level and keyed by a value-free signature §3.5. The paper gives no size limit, eviction rule or behaviour across processes. Cache hits skip the judge but still run the value checks, so the security argument rests on those checks app. A.1.
- Read auto-allow reduces utility on purpose. A read whose target comes from a tool output, such as a URL inside a file, is not auto-allowed. The paper names this as a utility loss and suggests selective human confirmation as a mitigation §4.4. It is not implemented in the reported results.
- Residual attack inside an authorised shape. The paper reports a Travel case under Important Instructions where all four calls were permitted, because the restaurant names were legitimately derived from an authorised list, yet the injection still steered the model's choice §4.4. ToolFence checks where a value comes from, not whether the model's choice follows the user.
- Denominators and counts. The paper gives 629 pairs (introduction, §4.1, appendix) and 609 scored pairs (table captions) tab. 1 tab. 4. Table 1's overall ASR is the average of the cross-tool and within-tool columns weighted by 524 and 85. For example, for No Defense (524 × 20.08 + 85 × 28.11) / 609 = 21.20, which matches. The derived numbers in this card use the same weighting.
- Small within-tool sample. The within-tool column uses 85 pairs, so one pair moves that ASR by about 1.2 points (1/85, derived). The text does not give confidence intervals per cell, though the figure captions mention error bars.
- Introduction ranges not in the tables. The introduction says Tool Filter's cross-tool ASR is 0 to 1.741% and within-tool ASR is 2.381% to 14.458% §1. These ranges do not appear in any table. They may be per-attack ranges read from fig. 2, but the paper does not say so.
- Overhead figures differ by place. The abstract and §4.5 give 1.63× for Qwen3-max. The introduction gives "1.9×" and Table 2 gives 1.90× for the full system. The paper does not clearly say which configuration and which timing measure each number uses. §4.5 gives 3.79× for GPT-4o. The source LaTeX also contains a commented-out table that names GPT-5.4-nano for the same sample times, but the active text names GPT-4o only.
- Judge-call metric is undefined. "Judge calls per task" is reported without saying whether it averages over clean and attacked tasks or how it counts retries tab. 2 §4.3.
- Baseline ports. Tool Filter's second stage was changed for Mistral, because the original message history caused HTTP 400 errors on vLLM; the authors started a fresh conversation instead app. C.2.1. Spotlighting's delimiters raised error rates on Mistral app. C.2.2. Numbers against these baselines therefore depend on the authors' ports, not on the original implementations.
- Judge prompts are complete; the rest is not. The judge and grant prompts are printed in full app. B.1 app. B.2. The architect prompt, the provenance matcher, the budget values and the tool-loop settings are not.
- Scoring. Clean utility and utility under attack are computed by the AgentDojo verifier. Execution errors count as utility failures, not as attack successes §4.1.
Lineage
- Builds on / contrasts with: CaMeL, arXiv:2503.18813. ToolFence keeps the native tool loop and avoids CaMeL's custom pipeline and per-call data-flow analysis, which the paper says make CaMeL slow §1 app. A.3.
- Compared against: Repeat Prompt, Spotlighting and Tool Filter, from the AgentDojo benchmark §4.1 (AgentDojo is cited without an arXiv id in the source bibliography); PromptArmor, arXiv:2507.15219; SecInfer, arXiv:2509.24967; CaMeL, arXiv:2503.18813.
- Superseded by: not stated.
Source and license
Adapted from “ToolFence: Fine-Grained Authorization for Secure Tool-Using LLM Agents” by Yanjie Li, Xiangyu He, Xuelong Dai, Bin Xiao (arXiv:2609.37196), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors.