Defending Against Prompt Injection
Prompt injection is the SQL injection of LLM systems. Unlike SQLi, there is no perfect fix - only layers of defense.
Attack Vectors
- Direct injection (user input overrides system prompt)
- Indirect injection (malicious content in retrieved docs)
- Goal hijacking (user convinces model to ignore instructions)
Defense Layers
1. Input sanitization (detect and strip injection attempts) 2. Prompt structure (use XML tags, clear role separation) 3. Output validation (does response match expected schema?) 4. Least privilege (limit tool access) 5. Monitoring (alert on unexpected behavior)
Testing
PromptOps includes a safety pack with 200+ injection attempts. Run it on every prompt version. Track your defense rate over time.