Prompt Injection in AI Features: What OWASP, Anthropic and OpenAI Say to Do
Prompt injection happens when input changes an AI model's behavior in a way you did not intend, and you reduce the damage by limiting what the model can do, separating untrusted content from your instructions and requiring human approval for risky actions. No source claims it can be fully prevented. OWASP says it is unclear whether foolproof prevention exists, and OpenAI says structured outputs and isolation greatly reduce the risk without fully removing it. This guide summarizes the three sources as read on 10 November 2026.
Key facts
- OWASP separates direct injection, where a user's prompt alters the model's behavior, from indirect injection, where the model ingests external content such as a web page or file that contains instructions.
- OWASP lists these mitigations: constrain model behavior, validate output formats, filter inputs and outputs, enforce least privilege, require human approval for high-risk actions, segregate external content and run adversarial testing.
- Anthropic advises delivering third-party content to Claude only inside tool_result blocks, never in the system prompt or plain user text.
- OpenAI advises not using untrusted variables in developer messages and keeping tool approvals on for MCP tools.
- OpenAI states that structured outputs and isolation greatly reduce prompt injection risk but do not fully remove it.
Two threat models
Anthropic's guide splits the problem in two. In jailbreaks and direct prompt injection, the user of your application is the adversary and crafts inputs to bypass your guardrails. In indirect prompt injection, the user is trusted but the model processes third-party content such as web pages, emails, documents or tool results that contain adversarial instructions. OWASP draws the same line. The second case is the harder one for most products, because the attacker never talks to your application. They only need to put text where your model will read it.
OWASP also notes the possible impacts: disclosure of sensitive data, exposure of system prompts or infrastructure details, biased or incorrect output, unauthorized use of model functions, commands executed in connected systems and manipulated decisions. Those impacts grow with the tools and data your feature can reach.
Defenses against direct injection
- Screen the input. Anthropic suggests a lightweight model to pre-screen user input, with structured outputs so the verdict is a simple classification. It also suggests filtering for known injection patterns.
- Write the refusal behavior into the system prompt. Anthropic recommends stating ethical and legal boundaries and telling the model how to refuse.
- Respond to repeat offenders. Throttle or ban users who repeatedly try to get around the guardrails.
Defenses against indirect injection
- Keep untrusted content in tool results. Anthropic says Claude is trained to treat instructions inside tool results with appropriate skepticism.
- Label the content. Say what it is and where it came from, for example the body of an inbound email from an unknown sender.
- State the policy. Tell the model that content returned by tools, documents and searches is untrusted data and must never override the system prompt or the user's request.
- JSON-encode untrusted strings. Anthropic says escaping gives unambiguous delimiters between the payload and the surrounding structure.
- Use fixed structures between steps. OpenAI recommends schemas, enums and required field names, so there are no free-form channels for injected instructions.
- Screen tool output. Anthropic suggests passing each tool's raw output to a small classifier before the main model sees it.
Limit what a successful attack can do
OWASP and Anthropic both point to least privilege. Anthropic says to avoid giving the model secrets it does not need, run tools in sandboxed environments and scope permissions as narrowly as possible. OWASP lists least privilege and human approval for high-risk actions. OpenAI says to keep tool approvals on for MCP tools so a person can review and confirm each operation, and describes guardrails as an effective first wave of protection that is not foolproof. If a feature can send email, spend money or delete data, put a human confirmation between the model and that action.
Test it the way an attacker would
OWASP lists adversarial testing and Anthropic recommends red-teaming your own agent before deployment, using documents, emails and tool outputs that deliberately contain injection attempts. OpenAI recommends evals and trace grading to measure behavior. Add monitoring: Anthropic advises analyzing outputs regularly for signs of a successful injection and using what you find to refine prompts and filters.
What to do
- List every source of text your model reads that you do not control.
- Deliver that text as labelled data, in tool results or encoded fields, never inside your instructions.
- Remove tools and data the feature does not need, and sandbox the rest.
- Require human approval before irreversible or costly actions.
- Build a test set of injection attempts and run it on every prompt or model change.
- Log outputs and review them for signs of a successful attack.
For how costly these incidents are, see our coverage of IBM's breach cost figures for prompt injection and of the form-based injection found in Agentforce and Copilot. Compare security tools in the AI tool directory.
Questions people ask
What is indirect prompt injection?
It is when the model reads external content, such as a web page or file, that contains instructions that change its behavior.
Can prompt injection be fully prevented?
OWASP says it is unclear whether foolproof prevention exists, and OpenAI says structured outputs and isolation do not fully remove the risk. The practical goal is to limit the impact.
What is the single most useful control?
OWASP and Anthropic both name least privilege. A model that cannot reach sensitive data or take risky actions has less to lose when it is tricked.
Sources