Defending Against Prompt Injection With a Few DefensiveTokens

3Citations
Citations of this article
22Readers
Mendeley users who have this article in their library.
Get full text

Abstract

When large language model (LLM) systems interact with external data to perform complex tasks, a new attack, namely prompt injection, becomes a significant threat. By injecting instructions into the data accessed by the system, the attacker is able to override the initial user task with an arbitrary task directed by the attacker. To secure the system, test-time defenses, e.g., defensive prompting, have been proposed for system developers to attain security only when needed in a flexible manner. However, they are much less effective than training-time defenses that change the model parameters. Motivated by this, we propose DefensiveToken, a test-time defense with prompt injection robustness comparable to training-time alternatives. DefensiveTokens are newly inserted as special tokens, whose embeddings are optimized for security. In security-sensitive cases, system developers can append a few DefensiveTokens before the LLM input to achieve security with a minimal utility drop. In scenarios where security is less of a concern, developers can simply skip DefensiveTokens; the LLM system remains the same as there is no defense, generating high-quality responses. Thus, DefensiveTokens, if released alongside the model, allow a flexible switch between the state-of-the-art (SOTA) utility and almost-SOTA security at test time. The code is available here.

Cite

CITATION STYLE

APA

Chen, S., Wang, Y., Carlini, N., Sitawarin, C., & Wagner, D. (2025). Defending Against Prompt Injection With a Few DefensiveTokens. In Proceedings of the 18th ACM Workshop on Artificial Intelligence and Security, AISec 2025 (pp. 242–252). Association for Computing Machinery, Inc. https://doi.org/10.1145/3733799.3762982

Register to see more suggestions

Mendeley helps you to discover research relevant for your work.

Already have an account?

Save time finding and organizing research with Mendeley

Sign up for free