Prompt Injection Is a Systems Problem, Not a Prompt Problem
Prompt injection is an architecture problem before it is a model problem. If your AI system reads untrusted content and takes actions, you need hard trust boundaries, narrow tools, typed outputs, and adversarial evals.
LLM agents fail in ways standard web backends do not. They follow hidden instructions in fetched content. They leak internal prompts. They take actions across tools with weak boundaries. For a practitioner, the hard part is not model quality. It is system design.
Simon Willison’s “Week Progress” notes linked work on prompt injection and agent behavior. One useful fact from his writing is simple. If your model reads untrusted text, your system prompt is part of the attack surface. That point matters far beyond demos. It shapes how you build any AI workflow that reads documents, websites, tickets, code, or email.
If you ship AI features into a business system, you need a threat model for untrusted context. You also need tests that fail loudly before production does. The focus is less on abstract model safety and more on boring engineering. Define trust boundaries. Limit tool access. Record what the model saw and what it tried to do.
Treat every retrieved token as untrusted input
Most AI product failures start with a category error. Teams treat retrieved context as data. In practice, parts of it behave like instructions.
A model does not reliably separate these layers:
- user intent
- system policy
- retrieved documents
- tool output
- web page content
- code comments
- OCR text from images or PDFs
Once you accept this, your architecture changes.
What to inspect in your stack:
- Where untrusted text enters, RAG chunks, search snippets, support tickets, email bodies, CRM notes, Git diffs
- Whether the same model both reads content and decides actions
- Whether tool output gets fed back into the model without filtering
- Whether the model sees secrets, tokens, internal URLs, or hidden metadata in prompts
A common failure pattern looks like this:
- Your app retrieves a document.
- The document contains text aimed at the model, not the user.
- The model treats it as higher priority than you expected.
- The model calls a tool, reveals hidden instructions, or corrupts the result.
The fix starts with separation. Split readers from actors. Use one model or step to summarize untrusted material into a narrow schema. Use a later step to reason over the schema. Do not let raw retrieved text flow directly into action selection when you have any other option.
This also changes evaluation. Accuracy on a benchmark is weak evidence. You need adversarial corpus tests. Seed your retrieval store with hostile instructions and measure whether the agent follows them.
Reduce tool authority and scope
Tool use turns a bad answer into a bad action. The same prompt injection string has a different impact if the model only summarizes text versus if it can send email, issue refunds, edit tickets, or run shell commands.
So inspect tool authority before prompt wording.
Useful controls include:
- Separate read tools from write tools
- Require explicit user confirmation for side effects
- Bind each tool to narrow, typed parameters
- Reject free-form command strings when structured fields will do
- Enforce server-side policy checks after the model emits a tool call
- Rate-limit sensitive actions per session and per operator
- Attach resource scopes to credentials, not to prompts
Where teams often go wrong:
- A single agent holds broad API keys
- “Internal tools” trust the caller because it is the app
- The model chooses both the target and the action
- Hidden prompt rules try to block misuse, but the backend executes anything valid
The backend is your control plane. Put the guardrails there. If a tool sends payments, the service receiving the request should verify account, amount, policy, and approval chain independent of whatever the model wrote.
This is the same lesson security teams learned with web forms years ago. Client-side checks help UX. Server-side checks enforce reality. With agents, the model output is the client input.
Make prompt leakage and memory exposure testable
A lot of teams worry about jailbreaks in the abstract. A better frame is asset exposure. What private text does the model see, and under what conditions does it repeat or transform it?
Private assets often include:
- system prompts
- hidden chain-of-thought surrogates or reasoning summaries
- API endpoints and internal hostnames
- customer data from prior turns
- cached retrieval chunks from other tenants
- temporary task memory
You need specific tests for each class.
A practical test matrix:
- direct requests to repeat hidden instructions
- indirect requests embedded in retrieved pages
- multi-turn attempts to recover earlier context
- cross-tenant probes in shared caches
- file upload content asking for secret extraction
- tool output asking the model to reveal prior messages
What to log:
- prompt template version
- retrieval document IDs and chunk hashes
- tool call arguments before execution
- policy denials
- model output after redaction filters
- tenant and session boundaries
These logs matter for two reasons. First, they let you reproduce a failure. Second, they help you distinguish model weakness from architecture weakness. If the model leaked a secret because the secret sat in every request, the fix is not stronger wording. The fix is to stop exposing the secret.
If you want a fast check on your LLM setup, Prompt-Injection & System-Prompt-Leak Tester fits this stage well. Use it as a regression gate, not as a one-time exercise.
Constrain outputs with schemas, not prose
Prompt text like “never do X” has limited force when the model sees hostile context. Typed outputs and state machines hold up better.
For business systems, this means you should prefer designs like:
- classify into fixed labels
- extract into JSON with strict validation
- generate plans that a separate executor reviews
- produce SQL or code only inside a sandbox with checks
- map natural language onto approved operations with allowlists
Here is the engineering principle. Free text is hard to secure. Narrow interfaces are easier to verify.
A support triage agent is a good example. If the model outputs one of refund_review, account_access, billing_question, or abuse_report, you have a tractable control point. If it outputs an open-ended action plan with tool calls hidden in prose, you have an audit problem.
Common mistakes:
- parsing tool intent from natural language after generation
- accepting optional fields that alter authority, such as
admin=true - allowing the model to invent identifiers instead of selecting from server-issued ones
- skipping schema validation on retries because “the model usually gets it right”
Add deterministic checks at every boundary. If the model selects a ticket ID, verify it belongs to the current account. If it requests a database query, compile from an AST or approved template, not from raw text. If it writes code, run it inside strict resource limits with network access disabled by default.
Build an eval harness around real attack paths
Many agent teams have unit tests for prompts and none for security properties. That leaves a gap between demo quality and production behavior.
A useful harness covers the attack paths your system exposes:
- retrieved web pages with hidden instructions
- Markdown with prompt injection in links, alt text, and comments
- PDFs with OCR-visible payloads
- email threads with quoted hostile content
- source repositories with malicious README and issue text
- tool outputs that contain instruction-like strings
Score more than “did the answer look right.” Track:
- unauthorized tool-call rate
- prompt-leak reproduction rate
- policy-bypass rate
- cross-tenant retrieval error rate
- unsafe retry behavior after a denial
- variance across model versions
Keep these tests in CI. Model upgrades change behavior. So do prompt edits, retrieval changes, tokenizer changes, and tool wrappers. Your agent is a distributed system with a stochastic core. Treat regressions as normal engineering events.
One pattern works well in practice. Store adversarial fixtures alongside ordinary ones. For each fixture, define allowed tools, blocked tools, expected fields, and forbidden substrings. Then run the full chain, retrieval, prompt assembly, model call, validation, and execution gate. This gives you evidence about system behavior, not isolated prompt behavior.
What to watch next
The next phase of AI security work will focus less on chat interfaces and more on agent runtimes. Watch how vendors expose tool permissions, memory isolation, and provenance for retrieved context. Watch standards work around signed tool results and policy enforcement points. Most of all, watch your own logs. They show where your architecture asks a model to do security’s job, and where a narrower design would hold up better.