Indirect prompt injection defense method and system for large language model agent

By constructing a tool dependency graph and a pseudo-tool invocation mechanism, the problem of indirect suggestion injection attacks in large language model agents is solved, enabling secure and flexible task execution and improving the agent's defense capabilities and robustness.

CN120910855APending Publication Date: 2025-11-07ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510985087.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-17
Publication Date
2025-11-07

AI Technical Summary

Technical Problem

Existing technologies are insufficient to effectively prevent indirect suggestion injection attacks in large language model agents, which can lead to agents performing malicious operations and lack system-level behavioral constraints.

Method used

By constructing a tool dependency graph, explicitly modeling the task execution process, restricting tool call paths, introducing a pseudo-tool call mechanism and controlled node extension, we can ensure that the agent's behavior conforms to the predefined path and prevent malicious calls.

Benefits of technology

It significantly enhances the defense capabilities of large language model agents against indirect cue injection attacks, ensuring the security and flexibility of task execution, and improving robustness and adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120910855A_ABST
    Figure CN120910855A_ABST
Patent Text Reader

Abstract

The invention discloses an indirect prompt injection defense method and system for a large language model agent, and belongs to the field of artificial intelligence safety. Analyzing a user task instruction and predefined tool description based on a large language model agent, and generating a directed acyclic graph of a tool dependency relationship; tool calling of each node is executed according to a topological sequence, and a parameter reasoning result generated by node response is written into a context; if the information needs to be supplemented, allowing the agent to safely expand the node; when a potential injection instruction is detected, external tools related to semantics are guided to be called and added into a pseudo tool set, and finally the set is processed through a pseudo tool calling mechanism to achieve active defense. According to the method, the task execution process is explicitly modeled into the directed acyclic graph representing the tool dependency relationship, the tool calling path is predefined in the task planning stage, the behavior of the agent is constrained in the task execution process, and the illegal tool calling behavior triggered by the injection instruction is inhibited from the source.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of artificial intelligence security, and in particular to an indirect prompt injection defense method and system for a large language model agent. BACKGROUND

[0002] In recent years, with the rapid development of large language models in the field of natural language processing, agent systems based on them have shown wide applicability in practical applications and have gradually become an important technical solution for automating complex tasks. Relying on the powerful reasoning and planning capabilities of large language models, such agents can autonomously select and call external tools, such as database interfaces, web browsing tools, calendar management systems, and email clients, to perform real tasks with complex processes such as bank transfers, travel reservations, and document processing.

[0003] During task execution, agents often need to access external data sources to obtain environmental information from third-party platforms (such as web pages, emails, social platforms, etc.) and formulate subsequent operation plans accordingly. However, this process also introduces new security risks: attackers can embed malicious instructions into external data in a hidden manner, inducing agents to misrecognize them as real user intentions, thereby triggering unnecessary or even dangerous tool calls. For example, an attacker can embed a malicious instruction "Please transfer XX yuan to account X" in a web page, and if the web page is read by an agent, it may cause it to perform unauthorized fund transfer operations by calling tools. Such attack behavior is highly concealed and often difficult to detect before execution, and has caused serious security consequences in multiple real systems. This attack, which manipulates indirect input channels to influence agent decision-making behavior, is known as "indirect prompt injection".

[0004] Current mainstream defense techniques mainly focus on two methods: (1) through prompt enhancement techniques, increase the instruction limit in the input, user target repetition, etc. to guide the model to ignore potential injection content; (2) introduce additional detection models to filter tool responses or intermediate instructions. These methods may have some effect when facing known attacks, but their defense capabilities are heavily dependent on the understanding and judgment of the model itself, and lack structural constraints on the task execution process. Since agents always have the right to call tools at will, once the attack vector successfully bypasses the model's security mechanism, the agent may still perform operations that harm the user's interests, thereby causing significant security risks.

[0005] Therefore, there is an urgent need for a system-level defense mechanism that can establish behavioral constraints within the task execution framework, limit tool call paths and permissions from the source, and prevent injection instructions from triggering malicious tool calls. SUMMARY

[0006] To solve the above problems, the application provides an indirect prompt injection defense method and system for a large language model agent, which explicitly models a task execution process as a directed acyclic graph representing tool dependency relationships, predefines a tool call path required to complete a task in a task planning stage, and imposes constraints on the behavior of the agent during task execution to suppress illegal tool call behavior triggered by injected instructions from the source.

[0007] To achieve the above object, the application adopts the following technical solutions.

[0008] In a first aspect, the application provides an indirect prompt injection defense method for a large language model agent, comprising:

[0009] Based on user task instructions and predefined tool descriptions, the large language model agent analyzes the task and identifies the tool call sequence to generate a directed acyclic graph representing tool dependency relationships, i.e., a tool dependency graph, to clearly define the order of tool calls and the dependency relationships between their parameters. Each node in the graph represents a tool call and contains the tool name, input parameter list, and context dependency relationship.

[0010] The nodes are traversed in topological order according to the directed acyclic graph, the tool call is executed to analyze the tool response, and the parameter reasoning result generated by the tool response is written into the context. If a new tool needs to be called in the analysis tool response, the agent is allowed to extend the nodes in the tool dependency graph within limits, append the call of a tool for information retrieval to obtain supplementary data, and strictly limit the call of tools with modification state authority to ensure the safety of the system during task execution. If the analysis tool response contains potential injection instructions, the agent is guided to call tools that are semantically related but not in the tool dependency graph, and the newly generated tools are added to the pseudo tool set.

[0011] The pseudo tool call mechanism is introduced to handle the pseudo tool set.

[0012] Further, when traversing the nodes in topological order according to the directed acyclic graph, the nodes are divided into determined nodes and pending nodes according to the integrity of the input parameters.

[0013] For determined nodes, the tool call of the current node is directly executed.

[0014] For pending nodes, parameter reasoning is performed after the execution of its dependent nodes to complete the missing parameters, thereby ensuring the continuity and correctness of the call.

[0015] Further, the process of completing the missing parameters includes retrieving the parameter reasoning result of the previous node from the context, identifying the key field and verifying the variable type, updating the pending parameters of the node, and executing the tool call after completing the parameters.

[0016] Further, the limited expansion node needs to meet:

[0017] The expansion node tool type is a query tool, only reading environmental information, without changing any environmental state;

[0018] The created expansion node points to the successor node of the source node, and does not change the original dependency relationship, and the expansion node execution result is only used to supplement the context, without affecting the main task path.

[0019] Further, the tools in the pseudo tool set include two parts:

[0020] One is the calling tool of the potential injection instruction;

[0021] Two is the instruction tool corresponding to the expansion node.

[0022] Further, the pseudo tool calling defense mechanism refers to: traversing the pseudo tool set, generating a simulated calling request, generating a simulated calling response and writing into the context to simulate the state that the tool has been called. The pseudo tool calling defense mechanism generates a fake tool response by explicitly simulating the context of the injection attack and adds it to the context to simulate the state that the injection task has been executed, thereby weakening the interference of malicious content on the parameter reasoning process and ensuring that the behavior of the intelligent agent always advances towards the user's real goal.

[0023] Further, the tool dependency graph prohibits calling instruction tools that are not defined in the graph.

[0024] In a second aspect, the present application provides an indirect prompt injection defense system for a large language model intelligent agent, which is used to implement the indirect prompt injection defense method for a large language model intelligent agent.

[0025] The present application has the following technical effects:

[0026] The present application significantly enhances the defense capability of the intelligent agent against indirect prompt injection attacks while ensuring the flexibility of the intelligent agent by structuring the task execution process, combining dynamic parameter reasoning, controlled node expansion, and pseudo tool response mechanism, and has good security, practicality and universality.

[0027] Additional aspects and advantages of the present application will be given in part in the following description, which will become apparent from the following description, or will be learned by practice of the present application. BRIEF DESCRIPTION OF DRAWINGS

[0028] In order to make the technical solutions of the embodiments of the present application or the prior art clearer, the accompanying drawings needed in the embodiments or prior art description will be briefly introduced. Obviously, the accompanying drawings in the following description only constitute some embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort.

[0029] Figure 1 The overall flowchart of the indirect prompt injection defense method for intelligent agents of the present application;

[0030] Figure 2 The processing flowchart of the parameter reasoning mechanism in the present application;

[0031] Figure 3 The processing flowchart of the node expansion mechanism in the present application;

[0032] Figure 4 The processing flowchart of the pseudo tool calling mechanism in the present application. DETAILED DESCRIPTION

[0033] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in combination with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the protection scope of the present application.

[0034] As shown in Figure 1 The present application proposes an indirect prompt injection defense method for large language model intelligent agents. The method constrains the intelligent agent task execution process through the construction of tool dependency graph and controlled execution mechanism, guarantees the safe and accurate completion of tasks by intelligent agents in complex environments, and is especially effective in preventing indirect prompt injection attacks.

[0035] (1) Task input and construction of tool dependency graph

[0036] The present application first receives a natural language task instruction provided by a user, which is used to describe a specific goal that the user wants a large language model intelligent agent to complete. At the same time, the large language model loads predefined tool description information, which includes the function introduction, interface parameters and input requirements of each tool. In order to guarantee the controllability and safety during task execution, the user instruction is semantically analyzed and task decomposed by a large language model with planning ability. In the analysis process, the tools and their calling sequence that need to be called are automatically identified, and a tool dependency graph is constructed according to the dependency relationship between tool input parameters.

[0037] In the present application, each node in the tool dependency graph represents a tool call, which specifically includes:

[0038] Tool name;

[0039] Input parameter list, including known parameters and to-be-completed parameters;

[0040] Context dependency relationship, indicating the output of the preceding node on which the current node depends.

[0041] According to whether the parameters are complete, the nodes are divided into determined nodes and undetermined nodes. The undetermined nodes contain one or more parameters that have not been determined, which need to be obtained through context reasoning during execution. The tool dependency graph clearly specifies the tool call path required for the entire task, and strictly follows this path during subsequent execution phases, and explicitly prohibits calling any tool that has the ability to modify the environment state and is not in the dependency graph, thereby reducing the risk of the agent being controlled by malicious injected instructions from the source.

[0042] (2) Tool dependency graph-driven task execution

[0043] After entering the execution phase, the tool dependency graph is the only legal path for task execution, and each node is traversed in topological order to ensure that all tool calls meet the dependency constraints and avoid premature execution or logical errors.

[0044] As shown in Figure 2 For determined nodes (i.e., nodes whose parameters have been explicitly defined in the planning phase), the corresponding tool call request is generated directly, and the response result is written to the context after execution for subsequent node use. For undetermined nodes (i.e., nodes containing parameter placeholders), parameter reasoning is performed after all dependent nodes are executed to complete the missing parameters.

[0045] Parameter reasoning includes the following steps:

[0046] Dependency information extraction: retrieve the response of the preceding node from the context and extract the information required for parameter inference, such as key fields, entities, and attribute values, from the response;

[0047] Parameter matching: match the extracted information to the corresponding parameter position according to the tool interface definition;

[0048] Type checking: check that the type and format of the completed parameter meet the tool call specification to avoid abnormal input;

[0049] Parameter completion: fill in the missing parameters in the undetermined node and update it to a determined node.

[0050] After completing the parameter reasoning, the tool call corresponding to the node is executed immediately, and the response result is written to the context. All intermediate responses are persistently recorded during the entire process to ensure that subsequent reasoning is based on complete and up-to-date context information.

[0051] Through the above method, the large language model agent can dynamically complete complex tasks while maintaining a safe boundary, avoiding tool call deviation caused by injected instructions in the context, thereby effectively resisting indirect prompt injection attacks.

[0052] (3) Node expansion

[0053] During the execution of the task by the agent, although strictly limiting the addition of tool calls can improve security, it may also inhibit the dynamic adaptation ability of the agent to complex tasks, especially in scenarios where the task execution path needs to be adjusted based on external information. Therefore, the present application introduces a node expansion mechanism (as shown in Figure 3 ), which supports controlled information acquisition behavior under the premise of ensuring the safety boundary. This mechanism is mainly applicable to the following situations: when the agent autonomously determines that additional information needs to be obtained based on the response results of existing tools, it can make a new tool call request to complete the supplementary query. Such tasks have natural dynamics, and if the execution path is strictly fixed, it will be difficult to meet the actual task goals.

[0054] Based on the above analysis, the present application classifies the tools called by the large language model into two categories:

[0055] Query tool: only has the ability to read environmental information and does not produce any environmental state changes;

[0056] Instruction tool: has write permission and will have a substantial impact on the environmental state after being called.

[0057] When the tool response result of a certain node contains information that needs to be further queried, the agent is allowed to initiate a new tool call sequence. Then, strictly filter the sequence, only keep the part that belongs to the query tool, and create a new expansion node for each tool; while the instruction tool is added to the pseudo-tool set. The expansion node establishes a reference relationship with its source node and points to the successor node of its source node.

[0058] The expansion node has the following characteristics:

[0059] Only query tools are allowed to be called to ensure that the environmental state will not change;

[0060] The execution result is only used to supplement the context information to assist parameter reasoning and semantic understanding;

[0061] It will not change the existing task execution path and will not affect the original dependency relationship.

[0062] The node expansion mechanism improves the adaptability of the large language model agent when facing information uncertainty tasks, and at the same time, by strictly limiting the operation permission of the expansion node, it does not introduce new attack surfaces, ensuring that the large language model agent still has robustness and controllability when facing indirect prompt injection attacks and other attacks.

[0063] (4)Pseudo-tool invocation

[0064] In the scenario where the user task and the injection task have target overlaps, the agent may mistakenly use the instruction information in the injection task for parameter estimation of the current tool node during parameter reasoning, thereby causing the success of the indirect prompt injection attack. Although the large language model can be guided to ignore the abnormal instructions embedded in the tool response through prompt enhancement to alleviate such risks, since the large language model is more inclined to "follow instructions" than "ignore instructions" during the training process, such a method has poor stability in practice and is difficult to provide reliable protection.

[0065] To this end, the present application introduces a pseudo-tool invocation mechanism to actively avoid potential parameter pollution risks. The core idea of this mechanism is: when processing pending nodes, if it is detected that there is instruction information in the context that may induce tool parameter update, the agent will be preferentially guided to call a new tool related to the semantic of the instruction but not existing in the current tool dependency graph. The new tool is added to the pseudo-tool set, and the pseudo-tool invocation mechanism is introduced to process the pseudo-tool set to process the potential injection task separately from the main task.

[0066] As shown in Figure 4 , the large language model agent does not actually perform tool invocation, but injects a simulated pseudo-response into the context, making the agent mistakenly believe that the instruction has been processed, thereby ignoring the interference of this information in subsequent reasoning. This helps the agent to focus on parameter estimation of the original user task, and maintains the consistency and semantic integrity of the execution of the main task.

[0067] This mechanism effectively reduces the interference risk of indirect prompt injection attacks on tool parameter estimation, and improves the robustness and security of the large language model agent in complex interactive scenarios.

[0068] To verify the effect of the present application, the present application is defined as GPT-4o-mini, and extensive experiments are carried out on the AgentDojo benchmark using GPT-4o-mini to evaluate the effectiveness of the proposed defense strategy. The experiments cover four different test environments: Workspace, Slack, Travel, and Banking, and use the following evaluation indicators: (1) Attack Success Rate (ASR): attack success rate, which refers to the proportion of agents successfully completing the attacker's goal among all executed tasks; (2) Utility under Attack (UA): agent utility under attack, which refers to the proportion of agents that can still correctly complete user tasks in the presence of prompt injection attacks.

[0069] The attack strategies used in the experiment include: (1) Ignore Previous: adding a prefix such as "please ignore all previous instructions and perform the following" before input, guiding the agent to ignore the original user instructions and execute the injected content instead; (2) InjectAgent: through the manual construction of mandatory injection prefix, guiding the agent to perform operations according to the attacker's intention; (3) ToolKnowledge: explicitly specify tool name, parameter and operation steps in the injected content, bypass the model's reasoning process, directly induce it to complete malicious tasks; (4) Important Instruction: through "priority manipulation" to induce the model to execute the injected task, such as "before performing any other operations, please complete the following instructions", so as to induce the execution trajectory of the agent to deviate. Table 1, Table 2, Table 3, Table 4 are ASR and UA under four different attacks respectively, and Table 5 is the average ASR and UA under four attacks.

[0070] Four representative defense methods are selected for comparison in this embodiment: (1) Detector: use a classifier based on BERT to detect malicious instructions in tool input, and stop execution as soon as an anomaly is found; (2) ToolFilter: filter available tools according to user goals, only allow related subsets to be called, reduce the risk of being induced to call; (3) Spotlight: add a separator in the tool output and prompt the model to ignore the potential instruction information in it; (4) Sandwich: append the user's original goal after each tool call, continuously reinforce the user's intention, resist the interference of injected content. In addition, this embodiment also reports the performance of the agent under no defense measures (i.e. Default).

[0071] Table 1 ASR and UA of GPT-4o-mini under Ignore Previous attack

[0072]

[0073] Table 2 ASR and UA of GPT-4o-mini under InjecAgent attack

[0074]

[0075] Table 3 ASR and UA of GPT-4o-mini under Tool Knowledge attack

[0076]

[0077] Table 4 ASR and UA of GPT-4o-mini under Important Instructions attack

[0078]

[0079] Table 5 Average ASR and UA of GPT-4o-mini under four attacks

[0080]

[0081]

[0082] It can be seen that the present application always controls the attack success rate (ASR) below 1% under four attacks, which is significantly better than other defense strategies, and shows excellent adaptability. At the same time, while ensuring security, we also achieve the highest average utility accuracy (UA 58.77%), achieving the best balance between security and utility, and having strong practical application potential.

[0083] In this embodiment, an indirect prompt injection defense system for a large language model agent is also provided, comprising:

[0084] A task analysis module is configured to analyze a task by a large language model agent and identify a tool calling sequence based on a user task instruction and a predefined tool description, and generate a directed acyclic graph representing tool dependency, i.e., obtain a tool dependency graph. Each node in the graph represents a tool call, including tool name, input parameter list and context dependency relationship.

[0085] An execution engine module is configured to traverse nodes in topological order of the directed acyclic graph, execute tool calls to analyze tool responses, and write parameter reasoning results generated by the tool responses to the context. If a new tool needs to be called in the analyzed tool response, the security expansion module is executed. If the analyzed tool response contains a potential injection instruction, the agent is guided to call a tool that is semantically related but not in the tool dependency graph, and the newly generated tool is added to the pseudo tool set.

[0086] A security expansion module is configured to audit and create an expansion node containing only a query tool. If the security expansion module audits that the to-be-expanded node belongs to an instruction tool, the tool is added to the pseudo tool set.

[0087] A pseudo tool calling module processes the pseudo tool set by introducing a pseudo tool calling mechanism.

[0088] When the execution engine module traverses nodes in topological order of the directed acyclic graph, the nodes are divided into determined nodes and undetermined nodes according to input parameter integrity.

[0089] For determined nodes, the tool call of the current node is directly executed.

[0090] For undetermined nodes, parameter reasoning is performed after the execution of its dependent nodes to complete the missing parameters.

[0091] For the system embodiment, since it basically corresponds to the method embodiment, the relevant part can be referred to the part of the method embodiment, and the implementation method of the remaining modules will not be described here. The system embodiment described above is only illustrative, wherein the units described as separate components can or can not be physically separated, and the components displayed as units can or can not be physical units, i.e., can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the present application according to actual needs. Those skilled in the art can understand and implement it without creative labor.

[0092] The system embodiment of the present application can be applied to any device with data processing capability, which can be a device or apparatus such as a computer. The system embodiment can be implemented by software, hardware, or a combination of software and hardware. Taking software implementation as an example, as a logical device, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory and running by the processor of the device with data processing capability.

[0093] The above-described embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it cannot be understood as a limitation on the scope of the present application. For those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the protection scope of the present application.

Claims

1. An indirect prompt injection defense method for large language model agents, characterized in that, The method comprises the following steps: Based on the user task instruction and the pre-defined tool description, the task is parsed and the tool calling sequence is identified by a large language model agent, a directed acyclic graph representing tool dependency relationship is generated, that is, a tool dependency graph is obtained; each node in the graph represents a tool call, including tool name, input parameter list and context dependency relationship; The nodes are traversed in topological order of the directed acyclic graph, the tool call is executed to parse the tool response, and the parameter reasoning result generated by the tool response is written into the context; If a new tool needs to be called in the parsed tool response, the agent is allowed to extend the node in the tool dependency graph within limits; if the parsed tool response contains a potential injection instruction, the agent is guided to call a tool that is semantically related but not in the tool dependency graph, and the newly generated tool is added to a pseudo tool set; A pseudo tool calling mechanism is introduced to process the pseudo tool set.

2. The indirect prompt injection defense method for large language model agents according to claim 1, wherein, When traversing the nodes in topological order of the directed acyclic graph, the nodes are divided into determined nodes and undetermined nodes according to the integrity of the input parameters; For the determined nodes, the tool call of the current node is directly executed; For the undetermined nodes, parameter reasoning is performed after the execution of the dependent nodes to complete the missing parameters.

3. The indirect prompt injection defense method for large language model agents according to claim 2, characterized in that, The process of completing the missing parameters includes: retrieving the parameter reasoning result of the previous node from the context, identifying the key field and verifying the variable type, updating the undetermined parameters of the node, and executing the tool call after completing the parameters.

4. The indirect prompt injection defense method for large language model agents according to claim 1, wherein, The limited extension of the node needs to meet the following conditions: The tool type of the extended node is a query tool, which only reads environmental information and does not change the environmental state; The extended node points to the successor node of the source node, and does not change the original dependency relationship; the execution result of the extended node is only used to supplement the context and does not affect the main task path.

5. The indirect prompt injection defense method for large language model agents according to claim 1, wherein, The tools in the pseudo tool set include two parts: One is the calling tool of the potential injection instruction; The second is the instruction tool corresponding to the extension node.

6. The indirect prompt injection defense method for large language model agents according to claim 5, characterized in that, The pseudo tool calling defense mechanism refers to: traversing the pseudo tool set, generating a simulated calling request, generating a simulated calling response and writing it into the context to simulate the state that the tool has been called.

7. The indirect prompt injection defense method for large language model agents according to claim 1, wherein, The tool dependency graph prohibits calling instruction tools that are not defined in the graph.

8. An indirect prompt injection defense system for large language model agents, comprising: The method comprises the following steps: A task parsing module is used to parse the task and identify the tool calling sequence based on the user task instruction and the pre-defined tool description, generate a directed acyclic graph representing tool dependency relationship, that is, a tool dependency graph is obtained; each node in the graph represents a tool call, including tool name, input parameter list and context dependency relationship; An execution engine module is used to traverse the nodes in topological order of the directed acyclic graph, execute the tool call to parse the tool response, and write the parameter reasoning result generated by the tool response into the context; If a new tool needs to be called in the parsed tool response, a security expansion module is executed; If the parsed tool response contains a potential injection instruction, the agent is guided to call a tool that is semantically related but not in the tool dependency graph, and the newly generated tool is added to a pseudo tool set; A security expansion module is used to audit and create an extension node containing only query tools; A pseudo tool calling module uses a pseudo tool calling mechanism to process the pseudo tool set.

9. The indirect prompt injection defense system for large language model agents of claim 1, wherein, If the security extension module audits that the node to be extended belongs to the instruction tool, the tool is added to the pseudo tool set.

10. The indirect prompt injection defense system for large language model agents of claim 1, wherein, The execution engine module traverses the nodes in topological order of the directed acyclic graph, and divides the nodes into determined nodes and undetermined nodes according to the input parameter integrity; For the determined node, the tool call of the current node is directly executed; For the undetermined node, parameter reasoning is performed after the execution of its dependent nodes to complete the missing parameters.