Defending Against Prompt Injection with a Few Defensive TokensDefending Against Prompt Injection With a Few DefensiveTokens
The researchers propose DefensiveToken, a test-time defense method against prompt injection that inserts special tokens with safety-optimized embeddings before the LLM input. In safety-sensitive scenarios, system developers can prepend a small number of DefensiveTokens before the LLM input to obtain safety protection with minimal utility loss; when safety requirements are not high, they can be skipped directly, and the system maintains the same high-quality output as without defense. The authors claim that its prompt injection robustness is comparable to training-time defense schemes, allowing the system to flexibly switch between SOTA utility and near-SOTA security at test time. The code is open-sourced at https://github.com/Sizhe-Chen/DefensiveToken。