Skip to content
IAM Insights

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

share
15,154 words. With Sizhe Chen, author, UC Berkeley; Julien Piet, author, UC Berkeley; Chawin Sitawarin, author, UC Berkeley; David Wagner, author, UC Berkeley.
01

What's happening

Finding3
BI-FIND-2024-0046Lead finding

On 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."

high confidencebest source: independent researchobserved Feb 2024EvidenceSection 3
flag a problem with BI-FIND-2024-0046
BI-FIND-2024-0047

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.

high confidencebest source: independent researchobserved Feb 2024 – Jun 2024EvidenceStruQ designSection 4
Also reported in +1 briefing
flag a problem with BI-FIND-2024-0047
Figure steps
  1. 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.
  2. 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.
  3. 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.
  4. The model, fine-tuned on examples with instructions planted in the data, answers the prompt's question and ignores the leftover instruction.
Fig. 1

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 →

BI-FIND-2024-0048

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.

high confidencebest source: independent researchobserved Feb 2024EvidenceSection 4Section 1
flag a problem with BI-FIND-2024-0048
02

Section by section

4

showing 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

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

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

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

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

Terms used

StruQ
A prompt-injection defense that sends the prompt and the untrusted data to the model as two separate inputs, and trains the model to obey only the prompt.
Prompt injection
Hiding instructions in text an AI model reads, such as an email or a web page, so the model does something its operator never asked for.
Greedy Coordinate Gradient (GCG)
An attack that searches for a string of odd-looking tokens to add to a prompt so a model does what the attacker wants, first built for jailbreaks.
AlpacaEval 2
A benchmark in which a GPT-4-based judge compares a model's answers with a reference model's answers.
BIPIA
A benchmark and fine-tuning defense for indirect prompt injection, by Microsoft-affiliated researchers.
Application programming interface
Application programming interface: a defined way for software components to request operations or exchange data.
Jailbreak
A prompt or technique that gets an AI model to bypass its safety safeguards; a 'universal' jailbreak works broadly across topics, a narrow one only in specific circumstances.
Instruction hierarchy
A training technique that teaches a model to rank instructions by source, so text from a tool or web page loses to the system prompt.

Read next

Was this briefing useful?

Share this briefing

Every finding, forecast and open question on this site has a permanent ID. If we reword one, its ID stays the same, so a citation keeps pointing to the same claim.

Follow us on LinkedInRSS feed

Working on an identity problem this research touches? Talk to Boston Identity