Playbook · for Engineering, Security
Prompt injection defense in layers
Assume the model can be talked into anything. Limit what an injected instruction can reach, and check outputs before they act.
By Mr.DLast reviewed 3 min read
The uncomfortable truth
Prompt injection is first on the OWASP Top 10 for LLM applications (LLM01) because it has no clean fix. A language model reads instructions and data as the same stream of text, so any content it processes can try to steer it: an email it summarises, a web page it browses, a ticket, a PDF, a code comment, a tool's output. Filters catch the obvious cases. Research and real incidents keep showing that determined attackers get past them.
So the goal is not a model that cannot be fooled. It is a system where a fooled model cannot do much harm.
Direct and indirect injection
- Direct: a user types instructions meant to override your system prompt. Annoying, sometimes embarrassing, usually limited to what that user could already see.
- Indirect: instructions arrive inside content the model processes on someone else's behalf. This is the dangerous one, because the attacker never talks to your application and the victim never sees the payload.
Design for indirect injection and you cover direct injection too.
Layer 1: decide what the model may reach
Write down, for each LLM feature, which data it can read and which actions it can trigger. Then cut both lists to the minimum.
- Retrieval should respect the user's own permissions. A RAG pipeline that searches all documents for every user is a data-leak engine.
- Do not put secrets, credentials or other users' data in the context window. Assume anything in context can be repeated back.
- Split features: a summariser does not need tools; an agent that files tickets does not need email.
Layer 2: treat model output as untrusted input
OWASP calls this improper output handling (LLM05). Every place model output goes needs the same checks you would apply to user input:
- Never pass output straight to a shell,
eval, SQL or a template engine. Use parameterised calls and allowlists. - Render output as text, or sanitise HTML and strip active content. Markdown images and links can carry data out in their URLs, so restrict which domains they may load from.
- Validate structured output against a schema before acting on it.
Layer 3: control tools and actions
When the model can call tools, the tool layer is your real security boundary.
- Give each tool the narrowest permissions and inputs it needs, and check authorisation in the tool, not in the prompt.
- Require human confirmation for anything irreversible or outward-facing: payments, deletes, deploys, sending email or data outside the company.
- Show the user exactly what will happen before they confirm, using the real parameters.
Layer 4: mark and filter untrusted content
These measures lower the success rate; they are not a boundary.
- Separate trusted instructions from retrieved content with clear delimiters and tell the model the retrieved part is data.
- Use a prompt-attack classifier or guardrail on inputs, and a sensitive-data filter on outputs.
- Keep the system prompt free of anything you would mind leaking (OWASP LLM07).
Layer 5: log, test and respond
- Log prompts, retrieved sources, tool calls and outputs with enough context to reconstruct an incident, and protect those logs like the data in them.
- Red-team each feature before release with injected content in every input channel.
- Have a kill switch per feature, and an incident playbook entry for "the AI did something it should not have".
A quick test for your design
Imagine the model is fully controlled by whoever wrote the last document it read. If that person could read data they should not, or make your system act on their behalf, add a boundary at the tool or data layer. If the worst case is a wrong answer, you are in good shape.
What WardBee checks for this playbook
- Amazon Bedrock guardrail has prompt attack filter strength set to HIGH
bedrock_guardrail_prompt_attack_filter_enabled - Amazon Bedrock agent uses a guardrail to protect agent sessions
bedrock_agent_guardrail_enabled - Amazon Bedrock model invocation logging is enabled
bedrock_model_invocation_logging_enabled
Runs on each AWS sync while a framework it maps to, such as ISO 27001, is enabled. Run it on your account
Related standards: OWASP Top 10 for LLM Applications · NIST AI RMF


