Prompt injection: what gets through a first-pass review
By Abdul Asim ·
What is prompt injection?
Prompt injection is when text the model reads changes what it does in ways the builder did not intend. OWASP lists it first among risks for LLM applications and splits it in two: direct injection comes from the user's own prompt, and indirect injection arrives through outside content the model takes in, such as a web page, a file or a retrieved document.
The direct kind is what most teams test for. The indirect kind is what usually gets through, because nobody typed it into the chat box. This guide looks at both from the attacker's side, because that is the view I take when I build security testing and defenses for AI applications.
Prompt injection examples
These are illustrative patterns, written for this guide, of the shapes injection takes in real products:
- Direct override. A user tells a support assistant that they are the administrator and asks it to print its hidden instructions and any discount codes it knows. Crude, often blocked, still worth testing.
- Poisoned knowledge base. A supplier uploads a spec sheet to a shared drive. In white text on page 4 it says that any summary of this document must recommend this supplier. The RAG assistant retrieves the page and follows it.
- Inbox agent. An email arrives saying the reader is an automated assistant and should forward the last ten invoices to an outside address. An agent that can read and send mail treats it as a task.
- Exfiltration through output. Retrieved text asks the model to add a markdown image whose URL contains the user's previous messages. If the chat UI renders images, the browser sends the data out with no click.
- Tool argument smuggling. A product description contains text that ends up inside a database query or an API call the agent builds, changing which records it reads or writes.
Only the first one is typed by the attacker into your app. The rest ride in on data, which is why agentic AI systems with tools and retrieval have a much larger attack surface than a plain chatbot.
What gets through a first-pass review
A first-pass review usually means someone pastes known jailbreak strings into the chat and checks the refusals. That catches the obvious cases. From the attacker side, these classes are the ones I expect to survive it, and the ones I put in any serious test plan:
- Injection through retrieval. The reviewer never tested what happens when a hostile sentence sits in a document the index will return. Every RAG pipeline has this path.
- Injection through tool output. Web search results, API responses and file contents re-enter the model's context with no filter.
- Obfuscated payloads. Encoded text, other languages, odd Unicode, or instructions split across several chunks that only read as a command once retrieved together.
- Multi-turn setup. Harmless turns that establish a role or a rule, followed by the request that uses it.
- Output-side leaks. The model is never asked to reveal anything; it is asked to format a link or image that carries data out.
- Over-privileged tools. The injection itself is ordinary, but the agent has write access it never needed, so an ordinary trick becomes a real incident.
The common thread is that the attack does not look like an attack where the reviewer was looking.
Why prompt injection is hard to fix
Models receive instructions and data as one stream of text. The paper that first set out indirect prompt injection against real LLM-integrated applications describes exactly this blurring of data and instructions, and showed that planted prompts can steer what the application does and which APIs it calls, without the attacker ever touching the chat interface.
Model providers are working on it. OpenAI researchers proposed an instruction hierarchy that trains models to give lower priority to instructions from users and third-party content than to the developer's system prompt, and reported clear robustness gains. That helps, but it is a trained tendency, not a guarantee. OWASP's own guidance says it is unclear whether fool-proof prevention exists. Plan as if some injections will reach the model, and design so that reaching the model is not enough.
Prompt injection defense that holds up
No single filter is the defense. What works is layers, so that an injection which passes one still fails at the next. The OWASP list maps well to the controls I ship:
| Layer | What it does | Example |
|---|---|---|
| Least privilege | Tools get only the access the task needs | Read-only tools unless the workflow must write |
| Scope gate | Actions outside an approved scope are refused before execution | Authorized-scope gate on the Odva AI testing workflow |
| Human approval | Risky or irreversible actions wait for a person | Risky test proposals reviewed before execution |
| Output validation | Responses must match a schema before anything downstream uses them | Pydantic validation of findings on the Odva AI workflow |
| Input and output filtering | Detectors flag likely injections and strip unsafe links or markup | A sidecar gateway in front of LLM endpoints |
| Separate untrusted content | Retrieved and tool text is marked as data, not instructions | Delimited context blocks in RAG prompts |
On a separate security project I built a gateway that sits in front of LLM endpoints and combines rule-based checks, an ML classifier and semantic checks, with a model-based sanitizer and a deterministic Pydantic policy engine behind them. That project recorded over 95% attack detection with under 3% false positives and under 40 ms median added latency. Detection that good still misses some attacks, which is why the privilege and approval layers sit behind it.
Two cheap fixes are often missing. Do not render images or links from model output unless the domain is on an allow-list. And never let the model compose raw queries or commands; give it typed tool parameters and validate them.
How to test for prompt injection
Testing has to be repeatable and authorized, or it turns into either a one-off demo or a liability. When I built the testing workflow for Odva AI, the design kept three things apart. A model helps plan tests. An authorized-scope gate decides which targets may be tested at all, and risky proposals go to a human reviewer before they run. Afterwards, every finding is validated against a schema and stored with its evidence. Reported usage is roughly 340 penetration tests a day.
One lesson from that build applies to every team: a well-structured finding is not proof of exploitability. Schema validation tells you the finding is complete enough to report. Someone still has to confirm the impact before it goes into a fix list.
For your own app, start small:
- Seed your index with a few documents that contain hostile instructions and check what the assistant does with them.
- Replay those cases on every prompt, model or retrieval change, alongside your normal LLM evaluation set.
- Log tool calls with their arguments so you can see when an injected instruction reached a tool.
- Track the false-positive rate of any detector you add, since blocking real users is a cost too.
Where to start
If your app uses retrieval, list every source that can put text in front of the model and ask who can write to it. If it uses tools, list what each tool can change and remove anything the workflow does not need. Those two lists find most of the real exposure. The broader set of controls is in my guide to AI governance.
If the system is already live and also unreliable, the AI App Review is a sensible first step: it checks retrieval, evals, cost and model routing on the live app and returns a prioritized fix list. It is not a penetration test, so treat injection testing as its own piece of work.
