StruQ: defending against prompt injection with structured queriesStruQ: Defending Against Prompt Injection with Structured Queries
The researchers propose StruQ, which uses structured queries to defend against prompt injection attacks on large language models, separating the prompt from user data into two channels, significantly improving resistance to prompt injection with little or no impact on usability. The system includes a secure front end that formats the prompt and user data into a special format, and a model specially trained to follow only the instructions in the prompt portion of the query; during training, a base (non-instruction-tuned) model is converted into a structured instruction-tuned model by adding to standard instruction-tuning data samples in which the data portion also contains instructions, and fine-tuning the model to ignore these instructions. Code is open-sourced at https://github.com/Sizhe-Chen/StruQ.