Briefing · Paper · source · updated · Boston Identity
StruQ held hand-written prompt injections to 2% or less on two small models; optimised attacks still got through
StruQ, from Sizhe Chen, Julien Piet, Chawin Sitawarin and David Wagner at UC Berkeley, hands a model the developer's prompt and the untrusted data as two inputs, with section markers the data cannot carry. Fine-tuned this way, Llama-7B and Mistral 7B shrugged off every hand-written injection the authors tried, at little cost in quality. Attacks that search for a working string got through less often, but they still got through.
arXiv · Sizhe Chen, Julien Piet, Chawin Sitawarin, David Wagner · February 9, 2024 · read
What's happening
Finding3On Llama-7B and Mistral 7B, the authors held hand-written injections to 2% success or less, while automated attacks still succeeded 9% to 58% of the time.
On their own tests of Llama-7B and Mistral 7B, Chen, Piet, Sitawarin and Wagner brought every hand-written prompt injection they tried down to 2% success or less; the strongest, Completion-Real, fell from 96% to 0% on both models. Attacks that search automatically for a working string still succeeded, less often: Tree-of-Attacks with Pruning (TAP) fell from 97% to 9% on Llama and from 100% to 36% on Mistral, and Greedy Coordinate Gradient (GCG) from 97% to 58% and from 99% to 56%. Quality on AlpacaEval barely moved, 67.2% to 67.6% on Llama and 80.0% to 78.7% on Mistral. The authors say their Llama model is "not completely immune to such attacks."
flag a problem with BI-FIND-2024-0046
On Llama-7B, defences that only add text to the prompt left Completion-Real working 39% to 85% of the time, while StruQ brought it to 0%.
StruQ changes the model, not the prompt. A front-end wraps the developer's prompt and the untrusted data in reserved marker tokens and strips those markers from the data, so the data cannot fake the end of its own section, and the model is fine-tuned on examples where the data carries a planted instruction and the right answer ignores it. Defences that only add text at run time did far worse on Llama-7B against Completion-Real, which succeeded 96% of the time undefended: a reminder in the prompt left it working 83% of the time, a reminder after the data 39%, delimiters around the data 85% and an in-context example 48%, against 0% for StruQ. BIPIA, an earlier fine-tuning defence the authors reproduced, cut AlpacaEval quality from 53.9% to 26.0% and still lost every GCG attack.
Also reported in +1 briefing
flag a problem with BI-FIND-2024-0047
Figure steps
- The developer's prompt and the untrusted data arrive as two inputs. Here the data, an email, ends with a fake response and a fake instruction section, as in the paper's Completion-Real attack.
- The front-end filter strips the reserved marker strings and "##" from the data, repeating until none are left, so the fake sections lose their markers.
- The front-end encodes the query with reserved tokens around each section. The data can no longer contain those tokens, so it cannot close its own section.
- The model, fine-tuned on examples with instructions planted in the data, answers the prompt's question and ignores the leftover instruction.
The attacker's text reaches the model only in the data slot, stripped of anything that could pass for a section marker, and the model has been trained to answer the prompt's instruction alone.
Drawn from the paper's figure 2 and its Completion-Real exampleSource dated February 9, 2024Passage: StruQ design
Swipe for the full figure →
The authors say StruQ protects only programmatic applications that call a model through an API and is not applicable to web-based chatbots.
In StruQ only the prompt slot carries instructions: what the application developer writes there is trusted, and everything in the data slot is not. The authors say it only protects programmatic applications that call a model through an API, is "not applicable to web-based chatbots", where they think users are unlikely to mark which of their words are instructions, and is not designed against jailbreaks or data extraction. They suggest future models accept a three-part query of system prompt, user prompt and data. They describe OpenAI's later instruction hierarchy, with system, user and tool-output levels, as one that "can be viewed as a generalization of StruQ", and say OpenAI deployed it in GPT-4o mini.
Section by section
4showing 4 of 4
[1]Prompt injection as the control/data-mixing flaw; threat model
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
AI trust
Prompt injection as the control/data-mixing flaw; threat model
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
The Berkeley authors file prompt injection with the 2600 Hz phone tone, SQL injection and cross-site scripting: one channel carries both control and data. Their answer is a structured query, where the prompt and the data travel separately. In their threat model the attacker writes the data, knows the prompt and the format, and cannot touch the prompt.
technical artifactfrom published text
[2]StruQ design: reserved-token front-end, filter, structured instruction tuning
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
AI trust
StruQ design: reserved-token front-end, filter, structured instruction tuning
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
A front-end wraps the prompt and the data in reserved marker tokens ([MARK], [INST], [INPT], [RESP], [COLN]) and repeatedly strips those strings, and "##", from the data. The model is fine-tuned from a base model on a set that is half clean examples and half examples with an instruction planted in the data, where the right answer ignores it. Figure 2 shows the pipeline.
technical artifactfrom published text + figures
[3]Results on Llama-7B and Mistral-7B, adaptive attacks, ablations
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
AI trust
Results on Llama-7B and Mistral-7B, adaptive attacks, ablations
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
On 208 AlpacaFarm samples per attack, every hand-written attack fell to 2% or less (Completion-Real 96% to 0% on both models). TAP fell from 97% to 9% on Llama and 100% to 36% on Mistral; GCG from 97% to 58% and 99% to 56%. AlpacaEval moved from 67.2% to 67.6% (Llama) and 80.0% to 78.7% (Mistral). The authors' own near-miss marker attacks reached 1% at most.
technical artifactfrom published text + figures
[4]Comparison with other defenses, limitations, future work
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
AI trust
Comparison with other defenses, limitations, future work
Sizhe Chen, UC Berkeley · Julien Piet, UC Berkeley · Chawin Sitawarin, UC Berkeley · David Wagner, UC Berkeley
Run-time defences on Llama-7B left the strongest hand-written attack working 39% to 85% of the time, against 0% for StruQ. BIPIA, reproduced, cut AlpacaEval from 53.9% to 26.0% and still lost every GCG attack. The authors limit StruQ to programmatic apps, not chatbots, and suggest a three-part query with a system prompt, citing the instruction hierarchy.
technical artifactfrom published text