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

Kwesi Cobbina, Tianyi Zhou · DOI

Abstract

In-context learning (ICL) relies on demonstrations to guide Large Language Models (LLMs). While demo selection and order are well-studied, this paper identifies a significant "positional bias" where the spatial placement of a demo block—relative to system instructions and user queries—can swing accuracy by up to 20% and flip nearly half of a model's predictions. We find that placing demonstrations at the start of a prompt (the "primacy effect") generally improves stability and performance, though optimal placement remains model-dependent.

Introduction: The Problem of Spatial Placement

In-context learning (ICL) has become the standard paradigm for interacting with Large Language Models (LLMs). Users typically provide a few "demonstrations" (demos) to steer the model toward a desired output format or reasoning path. While previous research has focused on which demos to select or their internal order, this study investigates a neglected dimension: spatial placement.

The authors define the "DPP bias" (Demos' Position in Prompt bias), questioning whether it matters if examples precede system instructions, follow them, or appear after the user's query. LLMs exhibit extreme sensitivity to these structural choices, leading to a brittleness that threatens the reliability of production systems.

Methodology

To isolate the effects of position, the researchers defined four canonical demonstration placements:

  • ssp (Start of System Prompt): Demos precede all instructions.
  • esp (End of System Prompt): Demos follow system instructions but precede the user query.
  • sum (Start of User Message): The standard default, where demos lead the user message.
  • eum (End of User Message): Demos are appended after the user's query.
Overview of the four demonstration positions (ssp, esp, sum, eum) and their impact on model performance.

The study introduced two metrics: Accuracy-Change ($\Delta_{metric}$), measuring performance shifts relative to zero-shot baselines, and Prediction-Change ($\Delta_{pred}$), quantifying "output volatility" by counting flipped predictions when moving demos from the default sum position.

Experimental Setup

The hypothesis was tested across ten open-source LLMs (Qwen, Llama3, Mistral, Cohere) ranging from 1.5B to 72B parameters. Evaluation spanned eight diverse tasks, including classification (AG News, MNLI), reasoning (ARC, MMLU), arithmetic (GSM8K), and summarization (XSUM).

Key Results and Insights

The Primacy Effect and Volatility

A consistent "primacy bias" emerged: placing demos early (ssp or esp) generally outperforms late placement (eum). For example, MMLU accuracy improved significantly under the ssp configuration compared to zero-shot. Conversely, the eum position proved highly disruptive; in QA tasks, it flipped over 30% of predictions without improving correctness, and in summarization, the flip rate reached nearly 100%.

Improvement in accuracy across different datasets based on demonstration placement, highlighting the primacy effect.

Model Sensitivity and Scale

Smaller models (1.5B–8B) are the most fragile, benefiting significantly from "positional tuning." While larger models (70B+) are more robust, they still exhibit non-trivial instability. Interestingly, there is no universal "best" position; while smaller Qwen models preferred ssp, Llama3-70B favored the sum position, suggesting that larger models might benefit from demos being closer to the query.

Underlying Causes

The authors hypothesize two primary drivers:

  1. Architectural: Autoregressive masking in causal-decoder LLMs means early tokens exert a disproportionate influence on the hidden states conditioning all subsequent tokens.
  2. Data-Driven: Instruction-tuning datasets often use fixed slots for demos, imprinting structural preferences during training.

Conclusion and Future Work

The study demonstrates that moving an identical block of demos can swing task accuracy by up to 20 percentage points. To mitigate this, future work should focus on test-time calibration to dynamically select optimal demo slots and robust training techniques, such as using randomly permuted contexts to encourage position-invariant representations.

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