Sub topic 7
Position Bias in Pairwise Comparisons
This chapter assumes you have prompted an LLM before, can read Python, and know what an evaluation set is. It also assumes you know the pairwise format, where a judge sees two answers to one question and picks the better one.
What position bias is
Position bias is a judge's tendency to prefer an answer because of where it appears in the prompt, not because of its quality. Some judges favor the first answer. Others favor the second. The size of the effect depends on the model, the prompt, and how close the two answers are in quality.
The bias is strongest when the answers are similar. If one answer is clearly wrong, most judges pick the right one in either order. If both are decent, the order can decide the result.
How to detect it
Run every pair twice, once as (A, B) and once as (B, A). Then count how often the verdict flips. A fair judge picks the same underlying answer in both runs. A judge that flips often is reacting to position.
Mitigation: swap and require agreement
The function below implements the diagram. It maps each raw verdict back to the original answer labels before comparing.
def judge_pair(call_judge, question, a, b):
"""call_judge(question, first, second) returns "first" or "second"."""
r1 = call_judge(question, a, b)
r2 = call_judge(question, b, a)
win1 = "A" if r1 == "first" else "B"
win2 = "B" if r2 == "first" else "A"
return win1 if win1 == win2 else "tie"In the first run, "first" means A won. In the second run, "first" means B won, because B was shown first. That is why win2 is mapped the other way. A judge that always says "first" gives A in run 1 and B in run 2. The two disagree, so the result is a tie.
You can test this with a deliberately biased fake judge:
def always_first(question, first, second):
return "first"
print(judge_pair(always_first, "Q", "answer one", "answer two"))This prints tie. The swap exposes the bias and does not let it decide a winner.
Reading the results
Track the tie rate along with the win rates. A high tie rate has two possible causes: the answers are really close, or the judge is strongly position-biased. To tell them apart, check the pattern of flips.
| Pattern in the swapped runs | Likely cause |
|---|---|
| Same answer wins in both orders | Real preference |
| Position 1 wins in both orders | Bias toward the first slot |
| Position 2 wins in both orders | Bias toward the second slot |
| Mixed flips with no pattern | Near-equal answers or high run-to-run variance |
Common errors
- Swapping the order but forgetting to map the verdict back, so the winner is credited to the wrong answer.
- Randomizing order once per pair and calling it fixed. Random order spreads the bias across answers on average, but each single verdict is still biased. Running both orders removes it per pair.
- Dropping ties from the report. Excluding them makes the win rate look more decisive than the evidence supports.
- Testing with only one slot labeled "Answer A". Labels such as "A" and "B" can add their own preference, so try neutral labels if you see a skew.
Exercise
A judge always picks the second answer shown. You run judge_pair on 100 pairs. What result does it return for each pair, and what does that tell you?
Show answer
It returns "tie" for every pair. In run 1 the judge picks B (second), and in run 2 it picks A (second, which is the original A). The two runs disagree each time. A 100% tie rate with this flip pattern shows strong bias toward the second slot, not equal answers.