Injection
Detect prompt injection attacks with 64+ patterns across 7 categories. Sub-millisecond, zero dependencies.
64+ regex patterns across 7 categories. Synchronous, zero dependencies, sub-millisecond. Import from governance-sdk/injection-detect.
Signature
ts
Basic Usage
ts
Return Type
ts
7 Attack Categories
| Category | Patterns | Description |
|---|---|---|
instruction_override | 6 | Override or replace original instructions |
role_manipulation | 4 | Redefine agent identity or persona |
context_escape | 3 | Leak system prompts or escape context |
data_exfiltration | 2 | Exfiltrate data to external endpoints |
encoding_attack | 2 | Bypass via base64, Unicode, encoding tricks |
social_engineering | 3 | Urgency, false authority, testing excuses |
obfuscation | 8 | Zero-width chars, RTL overrides, zalgo, Unicode confusables |
Severity Levels
| Level | Score Range | Description |
|---|---|---|
| low | 0.1-0.3 | Single low-weight pattern |
| medium | 0.3-0.6 | Multiple patterns or moderate-weight |
| high | 0.6-0.85 | High-weight or cross-category attack |
| critical | 0.85-1.0 | Multiple high-weight, cross-category |
Configuration
ts
Note: Custom patterns are evaluated alongside the built-in patterns. Use high weights (0.8+) for patterns specific to your domain.