Prompt Injection Defense
prompt injection defense · authorized defensive testing
Prompt Injection Defense
A layered defense guide covering trust boundaries, least privilege, human approval, output handling, monitoring, and safe verification.
Threat model first
Identify who can supply text, which documents the model reads, what data is reachable, what tools can be called, and where outputs are rendered. Prompt injection defense depends on these paths. A general instruction to ignore malicious text cannot by itself define access rights or prevent a downstream component from acting on unsafe output. Write down the security objective for each boundary.
Input and output filtering limits
Input filters can help classify or constrain known formats, but language, encoding, and context vary. Output filters can reduce unsafe links or markup, but they do not replace tool authorization. Test whether the filter fails open, whether a benign input is incorrectly blocked, and whether content is normalized before inspection. Treat filters as one layer with measurable scope, not a complete boundary.
Privilege separation
Give each tool only the permissions needed for its task. Separate retrieval identities by user and data class. Restrict destinations, validate arguments at the tool layer, and avoid ambient credentials in model context. A prompt can describe policy, but the enforcement point should reject unauthorized calls even if model behavior changes. Log denials and approvals for review.
Human approval for risky actions
Require an explicit human decision before sending, publishing, deleting, transferring, or changing high-impact data. Show the operator the action, destination, and relevant context; do not ask for a broad confirmation that hides the actual side effect. Verify that approval cannot be inherited from an untrusted document or prior unrelated turn. Use a mock path when testing.
Monitoring and response
Capture enough metadata to trace a suspicious input through retrieval, model version, tool call, approval, and output without logging unnecessary sensitive content. Define a response owner and a way to disable a connector or revoke a token. Exercise the response path using synthetic cases. NIST AI RMF and its GenAI Profile can help teams place these activities in a risk-management cycle.
Test your defences
Use direct and indirect cases, negative controls, and harmless markers in an authorized staging environment. Verify the actual access control and side effect, not just whether the model says “I cannot.” Re-run after model, prompt, retrieval, rendering, or permission changes. Document residual risks and cases not covered. There is no universal prompt-only defense or single test that guarantees safety.
Questions
Can prompt wording prevent prompt injection?
It can be one mitigation, but enforce permissions and output constraints in the application and tool layers as well.
Should I test defensive controls with real data?
Prefer synthetic records in an isolated environment; use production data only under explicit authorization and data-handling approval.
Try a rule-based local check: Open the browser-local prompt injection tester
Sources
- OWASP LLM01 Prompt Injection
- OWASP LLM02 Sensitive Information Disclosure
- OWASP LLM05 Improper Output Handling
- OWASP LLM06 Excessive Agency
- OWASP Top 10 for LLM Applications (2026 edition)
- NIST AI 600-1: Generative AI Profile
- NIST AI RMF Core: Govern, Map, Measure, Manage
- Source set checked 1 October 2026; this page was updated 6 October 2026.
Questions
Can prompt wording prevent prompt injection?
It can be one mitigation, but enforce permissions and output constraints in the application and tool layers as well.
Should I test defensive controls with real data?
Prefer synthetic records in an isolated environment; use production data only under explicit authorization and data-handling approval.