AI agent prompt injectionAgent input governanceAI agent securityAI agent governance

AI Agent Prompt Injection: How to Handle Untrusted Context

AI agent prompt injection tries to turn pages, documents, messages, or tool results into instructions. Learn where the trust boundary sits and how IT teams can limit actions, test failures, and keep evidence.

Abe Wheeler
Alignbase wordmark on a dark blue background.
Alignbase wordmark on a dark blue background.

AI agent prompt injection is an attempt to make an agent follow instructions hidden in material it was supposed to read as data. A user asks an agent to summarize a document. The document contains a command to send unrelated records elsewhere. The agent needs the document to finish the summary, but the document does not get to decide what tools the agent may call.

That is the trust boundary. NIST defines prompt injection as an attack that exploits untrusted input placed alongside a higher-trust prompt. The risk grows when an agent can act on what it reads through tools, persistent Memory, or another agent.

TL;DR

Mark outside content as data, keep the agent’s authority limited to its approved task, and enforce sensitive tool decisions outside the model. Validate action arguments and require approval for high-impact effects. Test with harmless hostile content, then inspect the tool decision and target-system result. A good instruction helps, but it is not an access control.

Where AI agent prompt injection enters a workflow

The attacker does not need to edit the system prompt. They may control a web page, search result, document, email, issue comment, database field, or tool response that the agent reads while doing legitimate work. OWASP’s prompt injection guidance treats remote content as untrusted input and recommends enforcing permissions and validating parameters at the tool boundary.

Input the agent reads Why it is useful Trust decision
Retrieved page or document Supplies facts for the requested task May be cited as evidence; cannot grant new authority
Email or chat message Supplies a request or background Sender identity and workflow scope must be checked before action
Tool response or API field Supplies current system state Data from a tool is not a new instruction source
Repository file or issue Supplies code and project context Untrusted contributors cannot change agent authority by writing text
Agent output passed to another agent Carries a result or handoff The receiving agent checks the source and its own authority

A string that says “ignore previous instructions” is an obvious test case. Real failures can be quieter: a document may claim an emergency approval, a tool result may provide a new destination for a report, or a page may tell the agent to save a fact in Memory. The attacker is trying to make source content control an action that the authorized user never requested.

Do not treat every quoted instruction as an attack. A policy document may describe rules the user asked the agent to summarize. The issue is whether the agent promotes that document’s text into authority over its own task, tools, or data access.

An authorized user request is an instruction to the agent within its granted scope. A message from an unverified sender or text quoted inside a document does not gain that status just because the agent can read it.

Put controls at the action boundary

Separate reading from acting. An agent can extract and summarize an outside page without receiving the ability to send messages, change records, or fetch unrelated data. When a workflow needs those actions, grant only the tools and scopes required for that task.

For each sensitive tool call, check the authenticated user, agent, workflow, target, requested operation, and material arguments at the tool or target system. Use a real approval service for high-impact actions and bind approval to the exact action and arguments. A prompt telling an agent to ask for approval does not block a tool call if the tool accepts it anyway.

The OWASP AI Agent Security Cheat Sheet recommends least-privilege tools, action checks, and tests for tool misuse, data leaks, and Memory poisoning. For managed agent instructions, keep a human owner and a review path. Outside pages, emails, and tool results should not be able to rewrite published instructions or silently become long-lived Memory.

This is also a reason to keep agent input governance distinct from tool authorization. Input governance helps decide which sources and versions enter a session. Authorization decides whether an action may happen. Both decisions need their own evidence.

Test the boundary with a harmless attack case

Write one normal task and one piece of outside content that tries to redirect it. Use a test record and a blocked destination, so a failed check cannot send real data or change production state. Keep the attempted instruction in the test fixture, then verify these outcomes:

  1. The agent completes or safely declines the authorized task without adopting the outside instruction.
  2. A requested tool call outside the approved scope is denied by the enforcing system.
  3. No protected data reaches the test destination, and no hostile instruction is saved as shared or persistent context.
  4. Logs identify the source, agent, run, attempted action, decision, and target-system result without storing secrets or private reasoning.

Repeat with different entry points, including retrieved documents, tool output, and agent-to-agent handoffs. Try a case without obvious attack phrases because a keyword filter can miss goal changes expressed in ordinary language. After a model, tool, retrieval, or policy change, rerun the cases that cross that boundary. The agent controls guide explains how to connect each test to an enforcement point and an owner.

If a case fails, preserve the untrusted source and action record, contain active work where the tool or host is controlled, and follow the incident response guide for investigation. Fix the failed boundary, then rerun both the malicious and normal task before restoring access.

Keep delivered context and observed behavior separate

In Alignbase, published Knowledge and Skills, working Memory, permissions, and independent routes help teams manage the context sent through supported integrations. Artifacts and Messages carry no instruction authority. Delivery audit can identify what was compiled or issued, with later stages supported only when separate evidence exists. It cannot prove the model consumed or obeyed a rule, and it cannot replace tool-side enforcement.

Alignbase can help teams keep approved instructions owned and current. The context injection guide explains how managed context reaches a session, which is different from the adversarial prompt injection discussed here. The IT and security leaders page shows how context control fits into wider agent oversight. For more on governing inputs and actions, see the Alignbase blog.

Frequently Asked Questions

What is AI agent prompt injection?

AI agent prompt injection is an attempt to make an agent treat lower-trust text as instructions that override its authorized task. The text may arrive in an attacker-controlled or unauthorized message, retrieved page, document, email, repository file, or tool response.

How is prompt injection different from context injection?

Context injection is the delivery of selected information or instructions into an agent session. Prompt injection is an adversarial attempt to cross a trust boundary by turning untrusted content into authority. The same input channel can carry useful task data or a malicious instruction, so source and scope matter.

Can a system prompt prevent prompt injection?

A clear system instruction helps define the task and trust boundary, but it cannot by itself guarantee that an agent will ignore hostile content. Protect sensitive actions with authorization, argument validation, least privilege, and approval at the tool or target-system boundary.

Where can indirect prompt injection enter an agent?

Indirect prompt injection can appear in web pages, search snippets, documents, emails, issue comments, database records, API responses, or tool output that an agent reads while doing an approved task. Treat those sources as data unless an authorized workflow explicitly promotes them to instructions.

What should IT test for prompt injection?

Use harmless adversarial content to test whether an agent changes goals, leaks protected data, calls an unauthorized tool, changes a high-impact action, or writes hostile text into persistent Memory. Check the actual tool decision and external result, not only the agent's explanation.

Does logging a delivered policy prove an agent resisted an attack?

No. A delivery record shows that a version was compiled or issued, and stronger integration evidence may show insertion. It does not prove the model consumed, obeyed, or applied the policy. Test the action boundary and inspect the resulting system record.

What should happen after a prompt injection attempt?

Contain any active high-risk action through the systems that control it, preserve the source material and relevant logs without copying secrets, determine what the agent actually did, fix the failed boundary, and rerun the test before restoring normal operation.