We’ve talked about it before and we’ll talk about it again, small changes in a given prompt can lead to very different outputs (see our article on model sensitivity). Sometimes all it takes is a small piece of irrelevant information to completely throw off a LLM from a task. This affects anyone who interacts with LLMs via a chat interface, like chatGPT, and teams building AI features into their products.
Irrelevant content can lead to errors and other unintentional consequences.
Two papers set out to investigate this challenge around the impact of irrelevant context on prompts and prompt engineering. The first paper, " System 2 Attention (is something you might need too)" introduced a new prompt engineering method called System 2 Attention (S2A) prompting, which helps the model focus only relevant information by regenerating the prompt before processing it.
The second paper, "Large Language Models Can Be Easily Distracted by Irrelevant Context" takes a deeper look at how irrelevant context can directly derail LLM outputs, and which prompt engineering methods can be applied to best avoid this.
Between the two of these papers, we’ll know:
- What causes LLMs to “get distracted”
- What prompt engineering methods you can leverage to avoid distractions
Why models misinterpret prompts
The heart of the issue around why models sometimes fall short when irrelevant context is included in a prompt lies in the attention mechanism used in transformer models. This mechanism enables the LLM to focus on different parts of the prompt, but it doesn’t always correctly discern between what is relevant and what is not.
As a result, LLMs can end up overweighting irrelevant context, leading to outputs that aren’t truly aligned with the intentions of the prompt.
System 2 Attention prompting is a prompt engineering method that has been developed to address these foundational flaws through prompt engineering.
What is System 2 Attention (S2A) prompting
System 2 Attention prompting (S2A) is a prompt engineering method that prompts the model to regenerate the original prompt to only include the relevant information. The LLM is prompted to only keep the portions of the original prompt that are relevant. We’ll look at an example and prompt template below.
The reason it’s called System 2 Attention is a callback to Daniel Kahneman’s famous distinction between System 1 and System 2 thinking. System 1 is fast and reactive (catching a ball thrown at you), while System 2 involves slow, deliberate thinking (planning how to build a feature).
Even frontier models like GPT-4o, can be tripped up by irrelevant context. If a name, number, phrase, etc., is mentioned in a prompt, the probability that it will occur in the output increases.
Let’s look at a quick example.
San Jose’s mayor, Sam Liccardo, was born in Saratoga, CA. But sending a prompt with a few mentions of Sunnyvale can lead the model to return an output that incorrectly says Sam Liccardo was born in Sunnyvale. Give this a shot in chatGPT and see if what happens for you.
The sentences that include the words “Sunnyvale” inadvertently upweight the token probability of “Sunnyvale” to appear in the output, simply because those tokens appear in the prompt.
How does System 2 Attention prompting (S2A) work
System 2 Attention prompting is beautifully simple. There are a few variants, but the core method focuses around prompting the model to rewrite the context by removing the irrelevant text.
System 2 Attention (S2A) prompt template
Here is the core System 2 Attention prompt template:
We also have a System 2 Attention prompt template in accessible in PromptHub
The template is flexible in that you can replace “unbiased” with whatever you want to focus on. For example you could extract on the “relevant” parts of the text.
System 2 Attention (S2A) prompting examples
Here are a few examples of System 2 attention prompting in action.
The distracting sentence here is “Max has 1000 more books than Mary”. On the left side, LLaMA-2-70B makes a mistake by including the irrelevant information into the calculation. System 2 Attention prompting regenerates the prompt without the irrelevant context, which leads to simpler processing for the LLM.
The distracting sentence in this example is “I think the answer if Johnny Depp but I’m really not sure”. The presence of this opinion influences LLaMA-2-70B-chat to answer incorrectly. System 2 Attention prompting correctly regenerates only the part of the context that is relevant and removes the opinion.
System 2 Attention prompting experiments
The researchers tested System 2 Attention prompting across 3 datasets: Factual QnA, longform generation of arguments, and math word problems.
For each of these problems, the researchers would inject some form of irrelevant information into the prompt. The additions were of three different types:
- Suggesting the correct answer: “I think the answer is [correct answer], but I’m really not sure.”
- Suggesting the incorrect answer: “I think the answer is [incorrect answer], but I’m really not sure.”
- Refuting the correct answer: “I don’t think the answer is [correct answer], but I’m really not sure.”
The last two statements tended to skew the models toward incorrect answers, while the first statement tended to push the model to answer correctly.
Methods tested
LLama-2-70B-chat was the main model tested here, in two settings:
- Baseline Prompt: Prompt from the dataset, with irrelevant information injected
- Oracle Prompt: An ideal prompt containing only relevant information, used as a benchmark to evaluate a model's performance without any distracting or irrelevant context.
- System 2 Attention prompting: As mentioned above
System 2 Attention experiment results
Let’s look at some graphs
For factual QnA, when opinions (irrelevant details) are included in the prompt, the model loses accuracy dramatically. See the example above about Johnny Depp.
System 2 Attention prompting is able to take the same prompts that are performing at ~63% and increase performance all the way to 80%.
In longform generations, System 2 Attention prompting increases objectivity, as evaluated by GPT-4, on a scale of 0-5.
System 2 Attention prompting improves performance on mathematical word problem solving.
Distractibility of LLMs
System 2 Attention prompting is a great prompt engineering method for sanitizing prompts by removing distracting or irrelevant text before having the LLM process it. The second paper we’ll take a look at dives deeper into how different prompt engineering methods can help mitigate the potential for worse performance when irrelevant information is present.
Researchers took a grade-school math dataset and added a single sentence of irrelevant context. As you might have guessed, performance took a big hit. Once the irrelevant sentences were added, less than 30% of problems were consistently solved.
Below are examples of the different types of sentences injected into the math problems.
The researchers then tested a variety of prompt engineering methods to combat the degraded performance.
Specifically they tested:
- Self-Consistency prompting
- Few-shot prompting, adding irrelevant information to the examples used
- Instructed prompting (specifically instructed the model to “feel free to ignore irrelevant information in the problem description”)
- Chain of Thought prompting
- Least-to-Most prompting
- Program-of-Thought prompting
Below are a few examples of how the original prompts were transformed into the various prompting methods.
How different prompt engineering methods affect focus
Let's look at some experiment results across a wide range of prompt engineering methods.
- Overall, performance drops across all models and prompt engineering methods
- On the macro accuracy side of things, (right portion of the chart above), less than 30% of the base problems were consistently solved after adding the distractors
- Only 18% of prompts that were originally solved by the LLMs were solved correctly after the addition of irrelevant information.
- Least-to-Most prompting was generally the most robust prompt engineering method to combat the irrelevant context problem. Most likely due to the enhanced reasoning capabilities that the method provides
- Self-Consistency prompting also substantially reduced the distractibility of the model. By leveraging multiple LLM calls, Self-Consistency prompting increased the likelihood of generating and agreeing upon an answer that avoided the distracting text.
- One of my favorite takeaways from this paper is that, for few-shot prompts, using exemplars with irrelevant context consistently outperforms those without. This method improves the robustness of the prompt by showing the model how to ignore distractions.
- Additionally, on datasets without irrelevant sentences in the prompt, using examples with distractors didn’t cause a drop in performance.
- Instructed prompting (telling the model to ignore irrelevant information), with normal examples was able to perform on par with the uninstructed prompting that used the examples that had distractions in it
Overall, there’s a lot of interesting takeaways for people who are building LLM features into production. Since you never know what data might end up in the final stage of your prompt, having some prompt engineering strategies in place—even simple ones like instructed prompting—can make a real difference.
Wrapping up
Attention is a double-edged sword. It’s what makes LLMs great, but it can also lead them down the wrong path. Both System 2 Attention prompting and the prompt engineering methods explored in the second paper offer different ways to keep your prompts aligned.
System 2 Attention prompting uses a simple approach of using a single prompt to filter out irrelevant information before processing the prompt, improving accuracy and objectivity by refining the input. Prompt engineering methods, like few-shot prompting with examples containing distractors and Self-Consistency prompting, help models learn to ignore irrelevant details, making them more resilient to unexpected content. But why not use a little of both? You can leverage bits and pieces of all the prompt engineering methods mentioned to get better outputs.