Aligning tool descriptions with implementations to detect prompt injection in LLM agentsAligning Tool Descriptions and Implementations to Detect Prompt Injections in LLM Agents
The authors use an LLM to check the consistency between tool descriptions and code implementations to detect tool poisoning, achieving 93.8% accuracy with Qwen3-14B on 503 tools.
The attacker controls or modifies the natural language description of a third-party tool and uses indirect prompt injection to hijack the agent into performing unauthorized operations; the attacker cannot access LLM weights, system prompts, or internal parameters, and the code implementation remains benign. The defender can inspect the description and source code before deployment and uses zero-shot detection.
- Third-party tool descriptions can embed hidden instructions that hijack LLM agents even when the user is benign. The authors argue that defenses that inspect only text struggle to identify tool poisoning disguised as normal operational requirements.
- Defense occurs before tool execution: an LLM first generates an objective code summary from the main implementation and helper functions, then checks whether the natural language description reflects only that implementation, and outputs a benign or injection verdict.
- The authors compare five backbones and four types of existing defenses on 503 tools. Qwen3-14B achieves 93.8% accuracy and 92.5% macro-F1; the authors report its accuracy is 16.7 percentage points higher than the highest baseline.
- The authors note that the method requires source code and cannot directly cover closed-source or remote MCP servers that expose only metadata, and that adaptive attacks such as code obfuscation were not evaluated. The experiments use five open-source backbones from 7B to 14B, and the number of repetitions is not reported.
- Evaluated models
- Qwen3-14BQwen3-8BPhi-4 (14B)Mistral-7BVicuna-7B
- Metrics
- AccuracyPrecisionRecallF1FNRFPR
The researchers propose a defense method that compares tool descriptions with code summaries to detect prompt injection in LLM agents. On a dataset of 503 samples comprising 377 prompt-injection tools and 126 benign tools, evaluated across five LLMs, the overall detection accuracy reaches 93.8%, compared with defense methods such as PromptArmor, DataSentinel, LLM-Based Detection, and Perplexity Filter.
Related events and news
1 events · 0 news mentions
- This event's paper
研究者比对工具描述与代码摘要检测提示注入
Paper analysis
What problem does this paper attempt to solve?
For covert prompt injection in tool descriptions, the authors propose checking the consistency between the description and the code implementation before execution.
Core problem: how to detect tool poisoning in third-party tool descriptions and prevent LLM agents from being hijacked by hidden instructions.
- Risk scenario: Tool-integrated agents can access external functions such as information, databases, and email; untrusted tool providers can hide instructions in descriptions or metadata, potentially triggering unauthorized tool calls even when the user is entirely benign.
- Existing gaps: The authors argue that defenses that filter user input or sanitize retrieved data leave a gap in tool interactions; standalone LLM classifiers easily overlook implicit injections disguised as operational requirements or parameter constraints.
- Core idea: Rather than judging in isolation whether a description is suspicious, compare the description with a summary of the code implementation to find unauthorized operations, unexpected behavior, and instructions that deviate from actual functionality.
- Proposed content: The authors propose a static consistency auditing defense and construct a 503-case test set containing 377 poisoned tools and 126 benign tools, comparing against existing defenses on five open-source LLM backbones.
- Threat model:
- Goal: Make the agent deviate from the user's task and perform attacker-specified data exfiltration, privilege escalation, or irrelevant tool calls.
- Knowledge: The attacker cannot access LLM weights, system prompts, or internal parameters.
- Capability: Can only provide or modify the natural language description of a third-party tool; the code implementation remains benign and contains no malicious payload.
- Victim system and defense conditions: A tool-integrated LLM agent that loads third-party tool descriptions; the defender can inspect descriptions and source code before deployment or execution, without needing a dynamic sandbox or execution traces.
What related research exists?
Related work is divided into tool poisoning, preventive defenses, and detection-based defenses; this paper uses code behavior as evidence for text auditing.
Tool Calling and Tool Poisoning
- Toolformer (Schick et al. 2023), ToolLLM (Qin et al. 2024): Study LLM use of external tools; the paper uses this to explain that agents read third-party tool schemas and descriptions to select and call tools.
- Greshake et al. (2023), Zhan et al. (2024), Debenedetti et al. (2024): Study indirect prompt injection and risks of tool-integrated agents, showing that malicious instructions can come from external content rather than a malicious end user.
- Wang et al. (2026), Li et al. (2026), Shi et al. (2025a): Study Tool Poisoning Attacks and tool selection attacks; the paper states that even if a poisoned tool is never called, hidden instructions may hijack model behavior.
Preventive Defenses
- Spotlighting (Hines et al. 2024): Distinguishes trusted instructions from untrusted data via rewriting or structured delimiters.
- Instruction Hierarchy (Wallace et al. 2024): Fine-tunes the model to prioritize higher-privilege instructions. The authors argue that preventive methods often struggle against tool poisoning because tool descriptions are typically loaded as privileged system-level context rather than untrusted user data.
Detection-Based Defenses and This Paper's Baselines
- Llama Guard (Inan et al. 2023), LLM Self Defense (Phute et al. 2023): Use an auxiliary or self-review LLM to check text for hidden adversarial intent.
- PromptArmor (Shi et al. 2025b): Detects and removes injected instructions from external text before execution; DataSentinel (Liu et al. 2025): Fine-tunes a detector with a minimax game against adaptive attackers.
- Baselines and data: Experiments compare PromptArmor, DataSentinel-S/L, LLM-Based Detection, and Perplexity Filter; baselines read only tool descriptions. Test sets come from Open Prompt Injection, MCP security bench, etc.; poisoning payloads are taken from BIPIA, InjecAgent, and MCPTOX.
The authors position this paper as a detection-based, LLM-assisted defense, with the distinction that it combines LLM reasoning with static code inspection, using implementation summaries to check descriptions rather than making isolated judgments on text alone.
How does the paper address this problem?
The method uses two prompts to separate code understanding from consistency auditing, then maps the structured verdict to benign or injection.
The overall approach is static consistency-verification: first have an off-the-shelf LLM summarize the actual code behavior of a tool, then check whether the natural language description accurately and exclusively reflects that behavior, completing detection before the agent executes.
Tool representation and defense objective
- Each tool is represented as T=(n,D,C,H), where n is the tool name, D is the description exposed to the agent, C is the main source implementation, and H is the helper functions called by C.
- The defense is a binary classifier f(T)→{benign,injected} that, by prompting an off-the-shelf LLM, aligns the semantic intent of D with the concrete functionality of (C,H).
- The defender does not know in advance whether a tool is poisoned, how many instructions it contains, or which attack strategy it uses; zero-shot prompting is used, with no task-specific fine-tuning for injection detection.
Implementation summary stage
- The tool name, main implementation, and helper functions are input, and the model is required to inspect the executable code and generate an objective natural language implementation summary.
- The summary covers inputs, core operations, side effects, and return values, and does not rely on the tool's promotional metadata, thereby separating code understanding from subsequent security auditing.
- Figure 2 gives the implementation summary prompt; its text focuses on "whether the description contains behavior not supported by the implementation," and together with the inputs and outputs described in the main text, constitutes this stage.
Consistency verification stage
- The generated implementation summary and the original description D are input, and the model is required to identify extra instructions, unauthorized side effects, and behavioral discrepancies.
- The output is a single JSON object containing five fields: tool_name, description, implementation_summary, match, and mismatch_reason.
- match being "yes" indicates that the description accurately and exclusively reflects the implementation, and it is judged benign; "no" indicates an inconsistency, and it is judged injected, with a brief reason for the discrepancy given.
- Figure 3 gives the complete verification prompt and output format constraints, including returning only JSON and the field rules.
Decision and exception handling
- Before parsing, auxiliary reasoning blocks (such as think tags) and Markdown formatting are removed, and then the match field in the JSON is read.
- Responses where JSON parsing fails or the match field is missing are recorded as unparseable (None), and are always counted as incorrect predictions in evaluation.
- Figure 1 shows the two-stage pipeline: the implementation goes into the Implementation Summarizer, the summary and description go into the Consistency Verifier, and the final output is Benign or Injected.
Dataset construction
- The test set has 503 cases in total, and each case stores six fields: tool_name, description, implementation, helper_implementation (when applicable), source, and gold_label.
- 126 cases are unmodified benign controls, and 377 cases are poisoned samples; the base tool definitions and implementations come from open-source repositories such as Open Prompt Injection and MCP security bench, and from tool-use benchmarks.
- Only the natural language description is modified; the code remains unchanged. Payloads come from datasets such as BIPIA, InjecAgent, and MCPTOX, and are added to benign descriptions at different positions.
- The two construction strategies are Direct Injection and Heuristic Context-Switching: the former directly appends or inserts instructions, while the latter inserts a transitional override phrase from existing indirect injection benchmarks between the benign description and the payload. Figure 4 gives an example of the second type.
What experiments did the paper conduct?
Qwen3-14B achieves 93.8% accuracy; backbone differences, false positives and false negatives, and baseline applicability conditions are the main experimental findings.
Experimental Setup
- Backbones tested: Qwen3-8B, Qwen3-14B, Phi-4 (14B), Mistral-7B, Vicuna-7B, all 7B to 14B open-source instruction-tuned models; the same prompt template and deterministic decoding are used.
- Dataset: 503 tools constructed by the authors, including 377 poisoned and 126 benign; all five backbones in Table 2 are evaluated on this set.
- Baselines: PromptArmor, DataSentinel-S, DataSentinel-L, LLM-Based Detection, and Perplexity Filter, all reading only the tool description D.
- Baseline implementations: LLM-Based Detection uses Qwen3-8B; Perplexity Filter scores with Vicuna-13B v1.3, and DataSentinel uses its released S and L checkpoints.
- Metrics: Poisoned is the positive class and benign the negative class; Accuracy, Precision, Recall, and F1 are macro-averaged over the two classes, FNR is the proportion of poisoned tools missed, and FPR is the proportion of benign tools falsely flagged.
- Verdicts and sample handling: The selected backbone itself generates the JSON verdict, with no independent judge model; None is counted as an error. Perplexity Filter is additionally calibrated on 63 benign tools and evaluated on the remaining 440 tools; the paper does not report the number of repetitions.
Main Results
According to Table 1, this paper's method uses Qwen3-14B; baseline conditions are given in the experimental setup, and values are in %.
Swipe horizontally to read the table
Method Acc. Prec. Rec. F1 FNR FPR PromptArmor 54.1 66.9 68.8 54.0 60.7 1.6 DataSentinel (L) 43.5 64.8 62.1 43.3 75.1 0.8 DataSentinel (S) 47.5 59.2 60.2 47.4 65.3 14.3 LLM-Based Detect. 77.1 88.3 54.4 51.4 0.0 91.3 Perplexity Filter 14.3 7.2 50.0 12.5 100.0 0.0 Our Method (Qwen3-14B) 93.8 94.1 91.1 92.5 3.5 12.7 - Authors' interpretation: This paper's method has accuracy 16.7 percentage points higher than the best baseline and macro-F1 38.5 percentage points higher; the authors argue that grounding in the code implementation helps distinguish normal operational instructions from injection payloads.
- Baseline exceptions: LLM-Based Detection has FNR of 0.0% but FPR of 91.3%; PromptArmor has FPR of only 1.6% while FNR is 60.7%, so they cannot be ranked by false negatives or false positives alone.
- Authors' attribution: The authors argue that Perplexity Filter struggles to distinguish tool injections written in fluent natural English from legitimate descriptions; DataSentinel's known-answer detection is not easily triggered by hidden tool injections.
Effect of Backbone Model
According to Table 2, all use this paper's method on 503 tools, and values are in %.
Swipe horizontally to read the table
Backbone model Accuracy Precision Recall F1 FNR FPR Qwen3-8B 92.1 90.9 91.5 91.1 7.4 9.5 Qwen3-14B 93.8 94.1 91.1 92.5 3.5 12.7 Mistral-7B 53.7 63.4 63.6 55.1 56.2 15.1 Phi-4 88.3 92.2 80.3 84.8 3.7 31.0 Vicuna-7B 23.1 56.7 44.2 21.8 98.1 0.8 - Qwen series: Qwen3-14B has the highest overall metrics; Qwen3-8B has a lower FPR of 9.5%, compared with 12.7% for Qwen3-14B.
- Other backbones: Phi-4's FNR is close to Qwen3-14B's, but it falsely flags 39/126 benign tools; Mistral-7B misses more than half of the poisoned tools.
- Vicuna-7B: Detects only 7/377 poisoned tools, with injection recall of 1.9% and FNR of 98.1%; the 2,048-token context makes 75 tools unevaluable, and another 65 outputs fail JSON parsing, all counted as errors.
Error Analysis
- Analysis target: The authors manually inspect all 31 misclassified and unparseable instances of Qwen3-14B, accounting for 6.16% of the 503 cases.
- False positives: 15 of the 126 benign tools are falsely flagged, FPR 12.7%; 14 of these are attributed to insufficient implementation descriptions, i.e., the description promises richer capabilities while the code only formats or simulates output, and 1 is a reasoning loop that fails to output the final JSON.
- False negatives: 16 of the 377 poisoned tools are missed, overall FNR 3.5%; in 14 cases the model ignores the injected instruction during comparison and misjudges the tool as benign, and 2 cases are attributed by the authors to payload hijacking, where the model deviates from the JSON format and outputs None.
Other Ablations and Analyses
- Perplexity Filter calibration: 50% of benign tools, i.e., 63 cases, are held out, the threshold is set at a 1% target FPR, and evaluation is on 377 poisoned and 63 benign tools.
- Perplexity Filter results: All 63 evaluated benign tools pass, FPR 0.0%; all 377 poisoned tools are missed, FNR 100.0%.
- DataSentinel-S/L: Both are evaluated directly on tool descriptions; Table 1 reports their accuracy as 47.5% and 43.5%, respectively.
- PromptArmor evaluation scope: Only its binary detection decision is used; text after removal of injected instructions is not evaluated.
- Statistics and reproducibility information: The paper does not report confidence intervals, statistical significance tests, or the number of repeated runs.
What are some points that can be further explored?
The authors list source code dependencies, adaptive attacks, and evaluation constraints, and plan to study layered defenses and continuous auditing.
Limitations and Future Directions Noted by the Authors
- Source code access limitation: The method requires implementations C and H, making it difficult to use for closed-source or remote MCP servers that expose only metadata (§7.1).
- Verifies consistency only: It verifies semantic consistency rather than intrinsic safety; if a malicious tool's description truthfully states harmful behavior, it will still be judged as match (§7.1).
- Adaptive attacks not covered: Attackers may add deceptive comments or obfuscated logic to source code to mislead the verifier, which the authors explicitly list as outside the current scope (§7.1).
- Depends on backbone capability: Detection performance varies with backbone reasoning capability; the authors illustrate this dependence with the accuracy difference between Qwen3-14B and Vicuna-7B (§7.1).
- Evaluation constraints: Baselines see only descriptions while this paper also sees code, so the comparison is not symmetric; legitimate explanatory metadata triggers false positives, and the 377-to-126 class imbalance may not cover the diversity of the production MCP ecosystem (§7.1).
- Future directions: The authors plan to study layered combinations of description filtering and code auditing, fine-tuning small models for code alignment tasks, automatic re-verification after tool definition changes, and extension to multilingual production MCP servers, adaptive code obfuscation attacks, and larger frontier models (§7.2).
Experimental Coverage
- The backbones tested are Qwen3-8B, Qwen3-14B, Phi-4, Mistral-7B, and Vicuna-7B, five in total, with parameter sizes from 7B to 14B (§5.4).
- The main evaluation uses 503 tools, including 377 poisoned and 126 benign; Perplexity Filter, due to calibration splitting, is evaluated only on the remaining 440 tools (§5.1, §6).
- Defense comparisons include PromptArmor, DataSentinel-S/L, LLM-Based Detection, and Perplexity Filter; baselines receive only natural language descriptions (§5.2, §6).
- Error analysis manually inspects Qwen3-14B's 31 misclassified and unparseable instances; the paper does not report inter-annotator agreement (§6.2).
- All backbones use the same prompt template and deterministic decoding; the paper does not report the number of repeated runs, number of queries, or end-to-end latency (§5.4).
Summarize the main content of the paper
The paper audits tool descriptions against code summaries and evaluates detection performance and error sources on a self-built 503-case dataset.
This is a study of pre-execution prompt injection defense for tool-integrated LLM agents, focusing on tool poisoning in third-party tool descriptions rather than malicious code itself.
- Problem: Untrusted tool providers can hide instructions in natural language descriptions, causing agents to deviate from user tasks. The authors argue that classifiers that inspect only text easily miss implicit instructions disguised as normal operational requirements.
- Method: An LLM first generates a code summary from the main implementation and helper functions, then checks whether the description accurately and exclusively reflects the implementation; it outputs a structured match verdict, and parse failures are uniformly counted as errors. The method is zero-shot and does not require dynamic execution.
- Data and comparison: The test set contains 377 poisoned tools and 126 benign tools, 503 cases in total; experiments compare five backbones, as well as PromptArmor, DataSentinel-S/L, LLM-Based Detection, and Perplexity Filter.
- Main results: Qwen3-14B achieves 93.8% accuracy and 92.5% macro-F1, with FNR of 3.5% and FPR of 12.7% (Table 2); the authors report its accuracy is 16.7 percentage points higher than the best baseline (Table 1).
- Backbones and errors: Qwen3-8B accuracy is 92.1%, and Vicuna-7B is 23.1% (Table 2). Among Qwen3-14B's 31 errors and unparseable instances, 15 are benign false positives and 16 are poisoned false negatives or None outputs (§6.2).
- Authors' conclusion: The authors argue that cross-checking metadata against executable logic helps detect tool poisoning; they also emphasize that the method requires source code and checks only consistency rather than intrinsic safety, and future work will study layered defenses, continuous auditing, and broader MCP evaluation.
Research lineage
6 foundations · 0 follow-ups in libraryNo later in-library follow-ups recorded yet.
Hover or focus a connected paper to inspect the citation context.