Where to show Demos in Your Prompt: A Positional Bias of In-Context Learning

Kwesi Cobbina, Tianyi Zhou

This paper, recently presented at EMNLP 2025, uncovers a significant but overlooked factor in Large Language Model (LLM) performance: the physical location of few-shot examples within a prompt.

TL;DR

Moving a static block of few-shot demonstrations from the beginning of a prompt to the end can swing accuracy by 20% and flip nearly half of a model's predictions. This "DPP bias" (Demos' Position in Prompt) suggests that for most models and tasks, placing demonstrations at the very start of the prompt—ideally within the system message—yields the most stable and accurate results.

What Problem Does This Paper Address?

In-context learning (ICL) is the backbone of modern LLM interaction, where we provide a few examples (demos) to "teach" the model a task on the fly. While researchers knew that the selection and internal order of these examples mattered, they largely ignored the structural layout of the prompt itself.

Most developers follow a "default" layout: System Prompt -> User Message (Demos + Query). This paper asks: Does it matter if the demos come before or after the system instructions? What if they come after the user's actual question? The authors discover that LLMs are incredibly sensitive to these spatial arrangements, a phenomenon they term DPP bias. This brittleness challenges the assumption that LLMs are robustly "reasoning" from context rather than just exploiting superficial structural patterns.

Methods

The researchers designed a systematic pipeline to test four canonical positions for a fixed block of five demonstrations:

  1. ssp (Start of System Prompt): Demos appear at the very beginning of the input.
  2. esp (End of System Prompt): Demos appear after system instructions but before the user message.
  3. sum (Start of User Message): The "default" where demos precede the query.
  4. eum (End of User Message): Demos are appended at the very end, after the query.

To quantify the impact, they introduced two task-agnostic metrics:

  • ACCURACY-CHANGE ($\Delta_{metric}$): The net gain or loss in performance compared to a zero-shot (no examples) baseline.
  • PREDICTION-CHANGE ($\Delta_{pred}$): The "volatility" or percentage of answers that flip when moving demos from the default sum position to another.

They tested these across 10 open-source models (Qwen, Llama3, Mistral, Cohere) ranging from 1.5B to 72B parameters.

Datasets

The study evaluated performance across eight diverse benchmarks:

  • Classification: MNLI (inference), AG News (topic).
  • Question Answering/Reasoning: ARC (science), MMLU (general knowledge), SQuAD (reading comprehension).
  • Arithmetic: GSM8K (math word problems).
  • Summarization: XSUM, CNN/DailyMail.
  • Long-Context: Booksum (chapters ~5k tokens).

Key Insights and Ideas

  • The Primacy Effect: There is a consistent "front-loading" advantage. Placing demos at the start (ssp or esp) generally outperforms placing them later. For example, MMLU saw an 18% accuracy boost under the ssp configuration.
  • The "End of Message" Disaster: Placing demos after the query (eum) is highly unstable. In QA tasks, this position flipped over 30% of predictions without improving correctness.
  • Architectural Roots: The authors hypothesize this bias stems from the nature of causal decoders. Because these models are trained with autoregressive masking, earlier tokens exert a disproportionate influence on the hidden state that conditions all subsequent predictions.
  • The Scaling Law of Robustness: Larger models (like Llama3-70B or Qwen-72B) are significantly more robust to positional changes than smaller models (1.5B–8B). However, even the giants remain sensitive when tackling complex reasoning tasks like GSM8K.
  • Proximity vs. Primacy: While smaller models crave the very beginning of the prompt, some very large models actually showed a slight preference for having demos closer to the query (sum), likely due to their superior ability to retain context over long sequences.

Key Results

  • Accuracy Swings: Simply moving the demo block can change task accuracy by up to 20 percentage points.
  • Output Volatility: On the AG News dataset, Qwen-1.5B saw 45.5% of its predictions change just by moving the demos.
  • Optimal Strategy: For most users, ssp (Start of System Prompt) is the "goldilocks" zone—it provides the highest accuracy gains and the lowest prediction volatility.
  • Task Sensitivity: Generative tasks (summarization) are far more volatile than classification tasks. In XSUM, the prediction change rate was nearly 100% for the eum position across almost all models.

Limitations and Future Work

The authors acknowledge several areas for further exploration:

  • Language Scope: The study focused exclusively on English data; positional biases might manifest differently in non-Western scripts or low-resource languages.
  • Model Diversity: While they tested four major families, they did not include proprietary models like GPT-4 or Claude, nor did they explore encoder-decoder architectures.
  • Mitigation Strategies: The paper suggests two promising paths for future work: Test-time calibration (using a small retriever to find the best demo slot for a specific query) and unbiased training (randomly permuting demo positions during instruction tuning to force the model to become position-invariant).

Summary updated

Abstract

In-context learning (ICL) is a critical emerging capability of large language models (LLMs), enabling few-shot learning during inference by including a few demonstrations (demos) in the prompt.However, it has been found that ICL's performance can be sensitive to the choices of demos and their order.This paper investigates an unexplored new positional bias of ICL for the first time: we observe that the predictions and accuracy can drift drastically when the positions of demos, system prompt, and user message in LLM input are varied.This bias, we refer to as DEMOS' POSITION IN PROMPT bias (DPP bias).We design a systematic evaluation pipeline to study this type of positional bias across classification, QA, summarization, and reasoning tasks.We introduce two metrics, ACCURACY-CHANGE and PREDICTION-CHANGE, to quantify net gains and output volatility induced by demos' position change.Extensive experiments on ten LLMs from four open-source model families (QWEN, LLAMA3, MISTRAL, COHERE) verify that the bias significantly affects their accuracy and predictions: placing demos at the start of prompt yields the most stable and accurate outputs with gains of up to +6 points.In contrast, placing demos at the end of the user message flips over 30% of predictions without improving correctness in QA tasks.Smaller models are most affected by this sensitivity, though even large models do remain marginally affected on complex tasks.12.
BibTeX
@misc{cobbina2025where,
  author = {Kwesi Cobbina and Tianyi Zhou},
  title = {{Where to show Demos in Your Prompt: A Positional Bias of In-Context Learning}},
  year = {2025},
  eprint = {2507.22887},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.22887},
}
Figure