Índice do artigofaltam 3 min de leitura
If a chatbot can be talked into ignoring its rules, it is not "smart".
It is out of control.
Prompt injection happens when an input (from the user, from a document retrieved through RAG or even from a tool) manages to change the model's behavior in an unwanted way: ignoring policies, revealing information, executing actions or producing dangerous output.
OWASP lists prompt injection as the first risk in its Top 10 for LLM applications (LLM01 in the 2025 edition, the most recent one published by the OWASP GenAI Security Project as of November 2026). In systems with RAG and tool calling, the impact can be larger because the model becomes a decision layer in the middle of the flow.
What you will learn
- The difference between direct and indirect injection
- Where injection gets into a modern system (RAG, tools, plugins)
- Layered mitigation that does not depend on "magic prompts"
- A checklist to reduce risk without killing the user experience
Direct vs indirect (the distinction that changes your architecture)
Direct injection is the classic one: the user writes something like "ignore all instructions and do X".
Indirect injection is more dangerous: the user does not write the malicious instruction.
It comes "hidden" in some content the model reads, for example:
- a document indexed in RAG
- an HTML page
- an email or ticket
- the output of a tool (a "compromised" external system)
In other words: RAG turns documents into input.
If you do not treat that as "untrusted input", the chance of an incident goes up.
What does not work (or barely works)
- "Putting a strong sentence in the prompt"
It helps, but it is not a security barrier.
- Trusting the model to "behave"
Models make mistakes, misread and can be manipulated.
- Putting permission rules in the prompt
Permission is a system rule. It must be enforced in the backend (not in the text).
The logic is similar to security in traditional apps: you do not trust user input, you validate it and enforce authorization on the server.
Layered mitigation (what usually works best)
Layer 1: Separate instructions from data (for real)
In the prompt, make it clear what is:
- "instructions" (system policy)
- "user input"
- "retrieved content"
And, above all, delimit the retrieved content.
Conceptual example (the exact format varies):
SYSTEM INSTRUCTIONS:
- Follow the policies below...
- Do not execute actions without validation...
USER INPUT:
<<< ... >>>
RETRIEVED CONTENT (UNTRUSTED):
<<< ... >>>This separation lowers the chance that the model "thinks" a document is a system instruction.
Layer 2: Treat RAG as an attack surface
Practical measures:
- index only trusted sources
- block "open" files that anyone can edit without review
- apply detection of suspicious content (keywords, jailbreak patterns)
- keep a trail: document → chunk → answer
Further reading: Sensitive data in RAG.
Layer 3: Reduce agency (fewer tools, fewer permissions)
When you give tools to the model (tool calling), you are giving it agency.
OWASP also treats "excessive agency" as a relevant risk (LLM06 in the 2025 edition: when the system allows too many actions with too much autonomy).
Rules that help:
- each tool does one thing (do not create "run any command")
- minimum permissions (read-only when possible)
- high-impact actions require human confirmation (human-in-the-loop)
Layer 4: Validate output before using it
LLM output is not "safe code".
If the model produces:
- JSON to call an API
- a query
- HTML/Markdown that will be rendered
- text that goes to another system
… you need to validate and sanitize it.
Common validations:
- strict schema (fields, types, enums)
- size limits
- allowlist of actions
- encoding/escaping before rendering
Layer 5: Observability and incident response
Without logs and metrics, prompt injection becomes a "rumor".
Log:
- tool calls and parameters (with redaction when there is PII)
- documents/chunks used (IDs)
- blocking events (by policy)
- rate of suspicious attempts
And treat it like any operational risk:
- alerts
- incident playbook
- fast rollback of prompt/model/configuration
If you want to structure this as a discipline, see: LLMOps: metrics and operations.
A straightforward checklist to reduce risk
- Clear delimitation between instructions, user and retrieved context
- RAG content treated as untrusted (includes validation/filtering)
- Tools with a specific function (avoid "open-ended tools")
- Minimum permissions per tool and per user
- Human confirmation for critical actions
- Output validation (schema, allowlist, size, sanitization)
- Rate limits and per-user limits (cost and abuse)
- Logs of tool calls, retrieved sources and policy blocks
- Regression tests covering jailbreak attempts and adversarial cases
References to go deeper
- OWASP Top 10 for LLM Applications
- OWASP Top 10 for LLMs 2025 (GenAI Security Project)
- LLM01: Prompt Injection (OWASP GenAI)
- LLM06: Excessive Agency (OWASP GenAI)
To bring this control into a real application, see how X-Apps structures governance and security in generative AI and LLMOps for AI in production.




