PreprintCited by 34Adversarial Robustness in Machine LearningSecurity and Verification in ComputingTopic Modeling

StruQ: defending against prompt injection with structured queries

Open access
Chen, Sizhe, Piet, Julien, Sitawarin, Chawin, Wagner, David·2024·arXiv

Abstract

Recent advances in Large Language Models (LLMs) enable exciting LLM-integrated applications, which perform text-based tasks by utilizing their advanced language understanding capabilities. However, as LLMs have improved, so have the attacks against them. Prompt injection attacks are an important threat: they trick the model into deviating from the original application's instructions and instead follow user directives. These attacks rely on the LLM's ability to follow instructions and inability to separate prompts and user data. We introduce structured queries, a general approach to tackle this problem. Structured queries separate prompts and data into two channels. We implement a system that supports structured queries. This system is made of (1) a secure front-end that formats a prompt and user data into a special format, and (2) a specially trained LLM that can produce high-quality outputs from these inputs. The LLM is trained using a novel fine-tuning strategy: we convert a base (non-instruction-tuned) LLM to a structured instruction-tuned model that will only follow instructions in the prompt portion of a query. To do so, we augment standard instruction tuning datasets with examples that also include instructions in the data portion of the query, and fine-tune the model to ignore these. Our system significantly improves resistance to prompt injection attacks, with little or no impact on utility. Our code is released at https://github.com/Sizhe-Chen/StruQ.

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Integrity signals

Registry

DataCite · 10.48550/arxiv.2402.06363

Cites

0 citation errors · 0 not checkable

Statistics

Claims the paper makes

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Claims other papers make about this one

Each is checked against this paper’s own text: does it say what the citing paper says it does?

  • Our work differs from Chen et al. (2024) in that we focus on a hierarchy of instructions with multiple levels, whereas they focus specifically on system messages versus user messages.

    “Our work differs in that we focus on a hierarchy of instructions with multiple levels, whereas they focus specifically on system messages versus user messages.”

    From The Instruction Hierarchy: Training LLMs to Prioritize Privileged Instructions (2024) · cites this paper as Chen et al., 2024

    The Prompt Injection Defenses section says StruQ has two types of messages—prompt and data—not system and user messages. Section 4.2 likewise describes training the model to follow instructions in the prompt but not the data. The paper treats system prompts as a possible future extension, so the claimed focus is contrary to its description of StruQ. (LLM, conf=0.90)

    Checked by a reasoning model — may be wrong.

    Experimental — accuracy not yet measured
  • Risks driven by write capability increase when T_execute is non-empty, while strong, non-bypassable gates reduce the likelihood that these risks propagate into executed actions.

    “Risks driven by write capability increase when T execute k ̸ = ∅, while strong, non-bypassable gates reduce the likelihood that these risks propagate into executed actions [1], [3], [100], [101], [99].”

    From Large language models for agentic NetOps and AIOps: Architectures, evaluation, and safety (2027) · cites this paper as [100]

    Section 4.2 describes a front-end that filters reserved delimiters so attackers cannot spoof the boundary between instructions and data, and the B.2 results show lower prompt-injection success rates for many attacks. The paper does not establish the claim about non-empty T_execute, write capability, or gates preventing risks from becoming executed actions; it evaluates LLM responses rather than downstream action execution. (LLM, conf=0.81)

    Experimental — accuracy not yet measured
  • Chen et al. (2024) proposed to train LLMs to ignore instructions provided in the user input.

    “In particular, Chen et al. (2024) proposed to train LLMs to ignore instructions provided in the user input.”

    From The Instruction Hierarchy: Training LLMs to Prioritize Privileged Instructions (2024) · cites this paper as Chen et al., 2024

    Section 4.4 (Structured Instruction Tuning) says the model is trained to ignore instructions in the data portion of a query while obeying instructions in its prompt portion. The claim omits that distinction: the paper does not propose ignoring all instructions provided in user input. (LLM, conf=0.84)

    Experimental — accuracy not yet measured
  • None of the heuristic prompt injection defenses provide any guarantee of security and regularly fall short to new attacks in practice.

    “Unfortunately, none of these heuristic defenses provide any guarantee of security and regularly fall short to new attacks in practice.”

    From Defeating Prompt Injections by Design (2026) · cites this paper as Chen et al., 2024

  • Chen et al. (2024) train models to completely ignore all instructions in the user messages, whereas we train models to conditionally follow lower-level instructions when applicable.

    “Moreover, they train models to completely ignore all instructions in the user messages, whereas we train models to conditionally follow lower-level instructions when applicable.”

    From The Instruction Hierarchy: Training LLMs to Prioritize Privileged Instructions (2024) · cites this paper as Chen et al., 2024

Self-check

Percentages, sums and reported differences re-computed from the paper’s own numbers.

The self-check needs the paper’s full text.

Cites

The publisher hasn’t deposited this paper’s reference list.

Research works printed but not linked: 43

  1. Hugo Touvron et al. Llama 2: Open foundation and fine-tuned chat models. arXiv:2307.09288, 2023. · arXiv
  2. Kai Greshake, Sahar Abdelnabi, Shailesh Mishra, Christoph Endres, Thorsten Holz, and Mario Fritz. Not what you've signed up for: Compromising real-world LLM-integrated applications with indirect prompt injec- tion. arXiv:2302.12173, 2023. · arXiv
  3. Yupei Liu, Yuqi Jia, Runpeng Geng, Jinyuan Jia, and Neil Zhenqiang Gong. Formalizing and benchmark- ing prompt injection attacks and defenses. In USENIX Security Symposium, 2024.
  4. Sam Toyer, Olivia Watkins, Ethan Adrian Mendes, Justin Svegliato, Luke Bailey, Tiffany Wang, Isaac Ong, Karim Elmaaroufi, Pieter Abbeel, Trevor Darrell, Alan Ritter, and Stuart Russell. Tensor Trust: Interpretable Prompt Injection Attacks from an Online Game. In International Conference on Learning Representations (ICLR), 2024.
  5. Fábio Perez and Ian Ribeiro. Ignore previous prompt: Attack techniques for language models. In NeurIPS ML Safety Workshop, 2022.
  6. Julien Piet, Maha Alrashed, Chawin Sitawarin, Sizhe Chen, Zeming Wei, Elizabeth Sun, Basel Alomair, and David Wagner. Jatmo: Prompt injection defense by task-specific finetuning. In European Symposium on Research in Computer Security (ESORICS), 2023.
  7. Alexander Wei, Nika Haghtalab, and Jacob Steinhardt. Jailbroken: How Does LLM Safety Training Fail? In Neural Information Processing Systems, 2023.
  8. Patrick Chao, Alexander Robey, Edgar Dobriban, Hamed Hassani, George J Pappas, and Eric Wong. Jail- breaking Black Box Large Language Models in Twenty Queries, 2023. arXiv:2310.08419. · arXiv
  9. Kaijie Zhu et al. PromptBench: Towards Evaluating the Robustness of Large Language Models on Adversarial Prompts. arXiv:2306.04528, 2023. · arXiv
  10. Jindong Wang et al. On the Robustness of ChatGPT: An Adversarial and Out-of-distribution Perspective. ICLR 2023 Workshop on Trustworthy and Reliable Large- Scale Machine Learning Models, 2023.
  11. Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne Lachaux, Timothée Lacroix, Bap- tiste Rozière, Naman Goyal, Eric Hambro, Faisal Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, and Guillaume Lample. LLaMA: Open and Efficient Foundation Language Models. arXiv:2302.13971, 2023. · arXiv
  12. Albert Q. Jiang et al. Mistral 7B, 2023. arXiv:2310.06825. · arXiv
  13. Anay Mehrotra, Manolis Zampetakis, Paul Kassianik, Blaine Nelson, Hyrum Anderson, Yaron Singer, and Amin Karbasi. Tree of attacks: Jailbreaking black-box LLMs automatically. arXiv:2312.02119, 2023. · arXiv
  14. Andy Zou, Zifan Wang, J. Zico Kolter, and Matt Fredrik- son. Universal and transferable adversarial attacks on aligned language models. arXiv:2307.15043, 2023. · arXiv
  15. Jason Wei, Maarten Bosma, Vincent Zhao, Kelvin Guu, Adams Wei Yu, Brian Lester, Nan Du, Andrew M Dai, and Quoc V Le. Finetuned language models are zero- shot learners. In International Conference on Learning Representations, 2021.
  16. Shengyu Zhang, Linfeng Dong, Xiaoya Li, Sen Zhang, Xiaofei Sun, Shuhe Wang, Jiwei Li, Runyi Hu, Tian- wei Zhang, Fei Wu, and Guoyin Wang. Instruc- tion Tuning for Large Language Models: A Survey. arXiv:2308.10792, 2023. · arXiv
  17. Yuntao Bai, Andy Jones, Kamal Ndousse, Amanda Askell, Anna Chen, Nova DasSarma, Dawn Drain, Stanislav Fort, Deep Ganguli, Tom Henighan, et al. Training a helpful and harmless assistant with reinforce- ment learning from human feedback. arXiv:2204.05862, 2022. · arXiv
  18. Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, et al. Training language models to follow instructions with human feedback. Advances in Neural Information Pro- cessing Systems (NeurIPS), pages 27730-27744, 2022.
  19. Jean Kaddour, Joshua Harris, Maximilian Mozes, Her- bie Bradley, Roberta Raileanu, and Robert McHardy. Challenges and applications of large language models. arXiv:2307.10169, 2023. · arXiv
  20. Hezekiah J Branch, Jonathan Rodriguez Cefalu, Jeremy McHugh, Leyla Hujer, Aditya Bahl, Daniel del Castillo Iglesias, Ron Heichman, and Ramesh Darwishi. Evaluat- ing the susceptibility of pre-trained language models via handcrafted adversarial examples. arXiv:2209.02128, 2022. · arXiv
  21. Jiahao Yu, Yuhang Wu, Dong Shu, Mingyu Jin, and Xinyu Xing. Assessing Prompt Injection Risks in 200+ Custom GPTs. arXiv:2311.11538, 2023. · arXiv
  22. Daniel Wankit Yip, Aysan Esmradi, and Chun Fai Chan. A novel evaluation framework for assessing resilience against prompt injection attacks in large language mod- els. In 2023 IEEE Asia-Pacific Conference on Com- puter Science and Data Engineering (CSDE), pages 1-5, 2023.
  23. Philipp Vogt, Florian Nentwich, Nenad Jovanovic, Engin Kirda, Christopher Kruegel, and Giovanni Vigna. Cross site scripting prevention with dynamic data tainting and static analysis. In NDSS, 2007.
  24. William G Halfond, Jeremy Viegas, Alessandro Orso, et al. A classification of SQL-injection attacks and coun- termeasures. In Proceedings of the IEEE international symposium on secure software engineering, 2006.
  25. Jingwei Yi, Yueqi Xie, Bin Zhu, Keegan Hines, Emre Kiciman, Guangzhong Sun, Xing Xie, and Fangzhao Wu. Benchmarking and defending against indirect prompt injection attacks on large language models. arXiv:2312.14197, 2023. · arXiv
  26. Eric Wallace, Kai Xiao, Reimar Leike, Lilian Weng, Jo- hannes Heidecke, and Alex Beutel. The Instruction Hierarchy: Training LLMs to Prioritize Privileged In- structions. arXiv:2404.13208, 2024. · arXiv
  27. Sander Schulhoff, Jeremy Pinto, Anaum Khan, Louis- François Bouchard, Chenglei Si, Svetlina Anati, Valen Tagliabue, Anson Liu Kost, Christopher Carnahan, and Jordan Boyd-Graber. Ignore this title and hack- aprompt: Exposing systemic vulnerabilities of llms through a global scale prompt hacking competition. arXiv:2311.16119, 2023. · arXiv
  28. Xuchen Suo. Signed-prompt: A new approach to prevent prompt injection attacks against llm-integrated applica- tions. arXiv:2401.07612, 2024. · arXiv
  29. Yinpeng Dong, Huanran Chen, Jiawei Chen, Zhengwei Fang, Xiao Yang, Yichi Zhang, Yu Tian, Hang Su, and Jun Zhu. How Robust is Google's Bard to Adversarial Image Attacks? arXiv:2309.11751, 2023. · arXiv
  30. Zeming Wei, Yifei Wang, and Yisen Wang. Jailbreak and guard aligned language models with only few in- context demonstrations. In International Conference on Machine Learning (ICML), 2024.
  31. Abhinav Rao, Sachin Vashistha, Atharva Naik, Somak Aditya, and Monojit Choudhury. Tricking llms into disobedience: Understanding, analyzing, and preventing jailbreaks. arXiv:2305.14965, 2023. · arXiv
  32. Gelei Deng, Yi Liu, Yuekang Li, Kailong Wang, Ying Zhang, Zefeng Li, Haoyu Wang, Tianwei Zhang, and Yang Liu. MasterKey: Automated jailbreak across mul- tiple large language model chatbots. arXiv:2307.08715, 2023. · arXiv
  33. Xinyue Shen, Zeyuan Chen, Michael Backes, Yun Shen, and Yang Zhang. "Do anything now": Characterizing and evaluating in-the-wild jailbreak prompts on large language models. arXiv:2308.03825, 2023. · arXiv
  34. Xiaogeng Liu, Nan Xu, Muhao Chen, and Chaowei Xiao. Autodan: Generating stealthy jailbreak prompts on aligned large language models. arXiv:2310.04451, 2023. · arXiv
  35. Nicholas Carlini, Florian Tramer, Eric Wallace, Matthew Jagielski, Ariel Herbert-Voss, Katherine Lee, Adam Roberts, Tom Brown, Dawn Song, Ulfar Erlingsson, et al. Extracting training data from large language models. In USENIX Security Symposium, pages 2633-2650, 2021.
  36. Weichen Yu, Tianyu Pang, Qian Liu, Chao Du, Bingyi Kang, Yan Huang, Min Lin, and Shuicheng Yan. Bag of tricks for training data extraction from language mod- els. In International Conference on Machine Learning (ICML), pages 40306-40320, 2023.
  37. Milad Nasr, Nicholas Carlini, Jonathan Hayase, Matthew Jagielski, A Feder Cooper, Daphne Ippolito, Christo- pher A Choquette-Choo, Eric Wallace, Florian Tramèr, and Katherine Lee. Scalable extraction of training data from (production) language models. arXiv:2311.17035, 2023. · arXiv
  38. Nils Lukas, Ahmed Salem, Robert Sim, Shruti Tople, Lukas Wutschitz, and Santiago Zanella-Béguelin. Ana- lyzing leakage of personally identifiable information in language models. In IEEE Symposium on Security and Privacy (SP), pages 346-363, 2023.
  39. Haoran Li, Dadi Guo, Wei Fan, Mingshi Xu, Jie Huang, Fanpu Meng, and Yangqiu Song. Multi-step jailbreak- ing privacy attacks on chatgpt. In The Conference on Empirical Methods in Natural Language Processing (EMNLP), 2023.
  40. Nikhil Kandpal, Matthew Jagielski, Florian Tramèr, and Nicholas Carlini. Backdoor Attacks for In-Context Learning with Language Models. In ICML Workshop on Adversarial Machine Learning, 2023.
  41. Aleksander Madry, Aleksandar Makelov, Ludwig Schmidt, Dimitris Tsipras, and Adrian Vladu. Towards deep learning models resistant to adversarial attacks. In International Conference on Learning Representations (ICLR), 2018.
  42. Yann Dubois, Chen Xuechen Li, Rohan Taori, Tianyi Zhang, Ishaan Gulrajani, Jimmy Ba, Carlos Guestrin, Percy S Liang, and Tatsunori B Hashimoto. Alpacafarm: A simulation framework for methods that learn from human feedback. In Advances in Neural Information Processing Systems (NeurIPS), 2024.
  43. David Glukhov, Ilia Shumailov, Yarin Gal, Nicolas Pa- pernot, and Vardan Papyan. Llm censorship: A ma- chine learning challenge or a computer security prob- lem? arXiv:2307.10719, 2023. · arXiv

Cited by

Sorted by citations

Authors
Chen, S., Piet, J., Sitawarin, C., & Wagner, D.
Affiliations
University of California, Berkeley (US)
Venue
arXiv
Publisher
arXiv
Published
2024
ISSN
2331-8422 (ISSN-L)
OpenAlex
W4391766701
Cited by
10
References
0
Citations by year
2026: 1 · 2025: 5 · 2024: 4
Type
posted content
Language
en
Open access
Locations
  • arXiv (Cornell University) (submittedVersion)
  • arXiv (Cornell University)
Funders
  • National Science Foundation (2229876, 2154873)
  • U.S. Department of Homeland Security
  • Open Philanthropy Project
  • King Abdulaziz City for Science and Technology
Topics
  • Physical Sciences › Computer Science › Artificial Intelligence › Adversarial Robustness in Machine Learning
  • Physical Sciences › Computer Science › Artificial Intelligence › Security and Verification in Computing
  • Physical Sciences › Computer Science › Artificial Intelligence › Topic Modeling
Keywords
prompt injection, structured queries, large language models, instruction following, instruction tuning, fine-tuning

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review