Evaluation · Advanced · 60-minute read
How to Measure and Reduce Position Bias in LLM-as-a-Judge

If an evaluator sees answer A before answer B, does it still choose A when the order is reversed? This guide builds a reproducible harness that swaps answer order, measures verdict flips, and treats disputed pairs as ties instead of pretending the evidence is decisive.
The problem: a judge can evaluate order, not quality
An LLM-as-a-Judge is a language model used to assess another model’s output. It is attractive because it is faster and cheaper to scale than human review, and because a natural-language rubric can cover dimensions that are difficult to encode as simple tests. But a judge does not observe “quality” directly. It observes a prompt, two candidate answers, a rubric, and the order in which those candidates were presented.
Position bias is the tendency to prefer an answer because of its displayed position, such as first or second, rather than because of its content. The practical risk is easy to state: if the judge selects answer A in one presentation and answer B after the same answers are swapped, the comparison is not stable enough to support a clean win for either answer.
This does not prove that the judge is useless. It proves that the evaluation protocol contains another variable. The order of presentation must be measured, reported, and controlled before aggregate rankings are trusted.
A concrete case
Suppose you are comparing two answers to the same customer-support question. Answer A is concise and gives a safe next step. Answer B is longer, includes a plausible explanation, but buries the next step near the end. You ask a judge to choose the better answer.
Original order:
Answer A: concise recommendation
Answer B: detailed explanation
Judge verdict: A
Swapped order:
Answer B: detailed explanation
Answer A: concise recommendation
Judge verdict: A
The second verdict still names the same underlying answer, so this pair is order-consistent. Now consider the following result:
Original order:
Answer A: concise recommendation
Answer B: detailed explanation
Judge verdict: A
Swapped order:
Answer B: detailed explanation
Answer A: concise recommendation
Judge verdict: B
If the judge’s “B” means the first displayed answer, the underlying answer selected in both runs is actually Answer B. If “B” means the answer with the stable candidate identifier, the result is different. This is why the harness must preserve stable candidate IDs and separately record displayed positions. A letter in a model response is not a reliable data model.
The correct unit of analysis is the pair of runs for one comparison, with the same prompt, rubric, candidate texts, model configuration, and candidate identities. Only the display order should change.
Define the measurement before calling the judge
Start with an explicit comparison record. Each row should identify the task, the two candidate answers, and the exact configuration used for both runs.
{
"pair_id": "support-0042",
"task_id": "support-0042",
"prompt": "How should a user rotate an exposed API key?",
"rubric_version": "support-v3",
"candidate_a": {
"id": "model-x",
"text": "..."
},
"candidate_b": {
"id": "model-y",
"text": "..."
},
"judge_model": "judge-model-id",
"temperature": 0,
"seed": 17
}
The example values are placeholders, not verified recommendations. Replace them with values supported by your provider and record the actual model identifier, sampling parameters, system prompt, rubric version, retry policy, and timestamp. If the provider does not guarantee a seed, do not describe the run as deterministic.
Use stable IDs such as model-x and model-y. Do not infer identity from the
answer text, output letter, or position. For each run, store both the displayed order and the normalized
choice.
| Field | Purpose |
|---|---|
pair_id |
Joins the original and swapped runs. |
display_order |
Records which stable candidate appeared first. |
raw_output |
Preserves the judge’s complete response for audit. |
parsed_choice |
Stores the extracted candidate ID, not only “A” or “B”. |
parse_status |
Separates valid verdicts from ambiguous or malformed outputs. |
request_fingerprint |
Helps verify that only candidate order changed. |
The paired swap design
For every pair, issue two requests:
- Present candidate A first and candidate B second.
- Present candidate B first and candidate A second.
Keep the task prompt, rubric, candidate content, judge model, generation settings, and parser constant. The only intended intervention is the position of the candidates. If the prompt contains phrases such as “the first answer,” update them so they refer to the displayed slots consistently in both runs.
A useful judge output schema is deliberately small:
{
"winner_id": "model-x",
"confidence": "high",
"reason": "..."
}
Treat winner_id as the machine-readable decision and reason as diagnostic
evidence. Do not let a parser recover a winner from a persuasive paragraph when the required field is
absent. An invalid or ambiguous output should be recorded as invalid, not silently forced into A or B.
If structured output is unavailable, require a strict marker such as
WINNER_ID=model-x. Still retain the complete raw response. A robust parser should reject
multiple markers, unknown IDs, missing markers, and answers that mention a candidate without explicitly
selecting it.
A minimal harness
The following Python-like example shows the protocol. The call_judge function is intentionally
left as an adapter because providers expose different APIs. The code is a reproducible reference for data
flow and normalization, not a claim that it has been executed here.
from dataclasses import dataclass
from hashlib import sha256
import json
from typing import Any
@dataclass
class Candidate:
id: str
text: str
def fingerprint(request: dict[str, Any]) -> str:
payload = json.dumps(request, sort_keys=True, ensure_ascii=False)
return sha256(payload.encode("utf-8")).hexdigest()
def build_request(task: dict[str, Any],
first: Candidate,
second: Candidate) -> dict[str, Any]:
return {
"system": task["judge_system"],
"user": {
"prompt": task["prompt"],
"rubric": task["rubric"],
"answer_1": {"id": first.id, "text": first.text},
"answer_2": {"id": second.id, "text": second.text},
"instruction": (
"Return JSON with winner_id, confidence, and reason. "
"winner_id must be one of the supplied stable candidate IDs."
)
},
"model": task["judge_model"],
"temperature": task["temperature"],
"seed": task.get("seed")
}
def parse_result(raw: dict[str, Any],
candidate_ids: set[str]) -> dict[str, Any]:
# Do not infer identity from answer_1/answer_2 after this point.
winner = raw.get("winner_id")
if winner not in candidate_ids:
return {
"parse_status": "invalid",
"winner_id": None
}
return {
"parse_status": "valid",
"winner_id": winner,
"confidence": raw.get("confidence"),
"reason": raw.get("reason", "")
}
def evaluate_pair(task: dict[str, Any],
a: Candidate,
b: Candidate) -> dict[str, Any]:
runs = []
for order, first, second in [
("a_first", a, b),
("b_first", b, a)
]:
request = build_request(task, first, second)
raw = call_judge(request) # provider-specific adapter
parsed = parse_result(raw, {a.id, b.id})
runs.append({
"pair_id": task["pair_id"],
"display_order": order,
"first_id": first.id,
"second_id": second.id,
"request_fingerprint": fingerprint(request),
"raw_output": raw,
**parsed
})
valid = [r for r in runs if r["parse_status"] == "valid"]
if len(valid) != 2:
pair_verdict = "invalid"
elif valid[0]["winner_id"] == valid[1]["winner_id"]:
pair_verdict = "stable"
else:
pair_verdict = "disputed_tie"
return {
"pair_id": task["pair_id"],
"runs": runs,
"pair_verdict": pair_verdict
}
Two implementation details matter. First, the parser returns stable IDs, so a verdict remains comparable after swapping display positions. Second, the pair verdict is computed only after both runs are available. Do not aggregate the first run immediately and “correct” it later; that makes partial data easy to misinterpret.
Metrics that expose order sensitivity
1. Valid-pair rate
Before measuring bias, measure whether the harness can produce valid paired decisions:
valid_pair_rate =
pairs_with_two_valid_runs / all_attempted_pairs
A low valid-pair rate is a protocol problem. It may indicate an unreliable schema, an overly complex rubric, model refusal behavior, truncation, or a parser defect. Do not hide invalid pairs by assigning them a winner.
2. Verdict-flip rate
A verdict flip occurs when the normalized winner changes after the candidate order changes:
flip_rate =
disputed_pairs / pairs_with_two_valid_runs
This is the most direct answer to the question “does the judge choose the same underlying answer in both orders?” A disputed pair should be treated as a tie for ranking purposes. It can remain visible in a separate diagnostic count.
3. First-position selection rate
To detect a directional preference, count how often the judge selects the candidate shown first:
first_position_rate =
first_position_wins / all_valid_runs
A rate above or below the midpoint can signal position preference, but it is not sufficient by itself. Candidate quality may be correlated with the order assignment, especially if the randomization is faulty. Report the assignment balance and calculate this metric on a balanced set.
4. Stable win rate
If disputed pairs become ties, the stable win rate for candidate A can be calculated as:
stable_win_rate_A =
stable_pairs_won_by_A /
(stable_pairs_won_by_A + stable_pairs_won_by_B + disputed_pairs)
This convention gives a disputed pair zero wins for both candidates. It is conservative: uncertain comparisons reduce the amount of evidence for a ranking instead of manufacturing a winner. If you also publish a conditional rate among stable pairs, label it clearly:
conditional_win_rate_A =
stable_pairs_won_by_A /
(stable_pairs_won_by_A + stable_pairs_won_by_B)
Never present the conditional rate without the number of disputed pairs. A candidate can appear dominant among stable pairs while the majority of all comparisons remain unresolved.
Confidence intervals and uncertainty
A point estimate such as “the flip rate is 8%” does not communicate how much data supports it. For a proportion, report the numerator, denominator, and an uncertainty interval. A confidence interval can be calculated with an exact binomial method or a suitable interval estimator.
For paired evaluation, resample complete pairs rather than individual runs. The two orders are dependent observations from the same comparison; splitting them during resampling breaks the design.
for each bootstrap replicate:
sample pair records with replacement
recompute:
valid_pair_rate
flip_rate
first_position_rate
stable_win_rate
take the requested percentile range
If you use a statistical library, record its version and interval method in the experiment metadata. Do not call a bootstrap interval “proof” that the judge is unbiased. It only quantifies sampling uncertainty under the assumptions of the resampling procedure.
The unit of sampling also matters. If many pairs come from the same task template, sampling individual pairs can make the interval look narrower than the variation across tasks. For a broader estimate, consider a hierarchical analysis or cluster resampling by task family. State which unit you used.
Make the randomization auditable
Randomization is useful only when it is real and inspectable. Generate an assignment plan before calling the judge and save it with the run:
pair_id,first_id,second_id
support-0001,model-x,model-y
support-0002,model-y,model-x
support-0003,model-x,model-y
For a balanced experiment, each candidate should appear first approximately equally often. Exact balance is convenient when the sample size permits it. If a failed request is retried, retry the same assigned order. Do not reroll the order during a retry, or the retry becomes a new experimental condition.
Save a content fingerprint for the rendered request. After both runs finish, compare fingerprints of the non-order fields or store a canonical request representation with candidate positions removed. This catches accidental changes such as a different rubric version, truncation, system prompt, or answer text.
Reducing position bias in the protocol
Use paired order swaps by default
The strongest practical control is to evaluate both orders and score only stable pairs as wins. This does not remove the judge’s internal preference, but it prevents one order from silently deciding the result.
Ask for criteria before the winner
A rubric can ask the judge to assess correctness, completeness, safety, and instruction following before selecting a winner. This makes the decision auditable, but it is not a guarantee against position bias. Criteria can themselves be affected by order, and a confident explanation can rationalize an unstable choice. Measure the paired outcomes anyway.
Separate candidate identity from display labels
Stable IDs should be opaque enough that they do not communicate rank or source quality. Avoid labels such
as best_answer, baseline, or new_model if they could influence the
judge. Keep display slots generic and map them back to stable IDs in your harness.
Use a tie option only with a defined rule
A judge may need to declare two answers effectively equivalent. If you allow a direct tie, define whether it is a substantive judgment or an error state. A disputed swap pair is a different kind of tie: it means the protocol did not produce a stable preference. Keep these categories separate in the data even if both contribute zero wins.
Repeat only when repetition answers a question
Multiple samples per order can help estimate stochastic variability, but they increase cost and complicate the analysis. If you repeat, predefine the aggregation rule. For example, aggregate within each order first, then compare the two order-level decisions. Do not choose the most favorable sample after inspecting the results.
Consider independent judges
A second judge model can reveal whether the observed order effect is specific to one evaluator. Agreement between judges is not proof of correctness, and disagreement is not proof of bias. Treat judge choice as another experimental factor and report it.
Verification checklist
Before trusting a report, verify the mechanics rather than reading only the aggregate table.
- Every completed pair has exactly two intended display orders.
- The same task prompt and rubric version were used in both runs.
- Stable candidate IDs are preserved in the raw request and parsed result.
- The parser rejects unknown, missing, or conflicting winner fields.
- Retries preserve the original order assignment.
- First-position assignments are balanced or the imbalance is reported.
- Raw judge outputs are retained for disputed pairs.
- Invalid pairs are not silently counted as wins or ties.
- Disputed pairs are excluded from candidate win totals.
- Aggregate rates include numerators, denominators, and uncertainty information.
- The report distinguishes stable wins, disputed ties, direct ties, and invalid outputs.
A useful test fixture contains deliberately simple cases: an identical pair, an obviously superior candidate, an order-sensitive mocked judge, an invalid JSON response, an unknown candidate ID, and a retry. The harness should classify each fixture as expected before you run it on real evaluation data.
Failure cases that commonly invalidate the result
Parsing the displayed letter as identity
If the original run maps A to model-x but the swapped run maps A to
model-y, comparing the letters produces a false conclusion. Normalize to stable IDs first.
Changing more than order
A different system prompt, rubric, answer truncation, or temperature means the two runs are not a clean swap test. Store request metadata and compare the rendered requests.
Counting only one side of a disagreement
Assigning the first run’s winner to the pair and treating the swapped run as a diagnostic note preserves the original bias. The pair is disputed until the protocol produces a stable decision.
Retrying until the preferred answer wins
A retry policy that stops when a desired verdict appears is outcome-dependent sampling. Define retry limits and invalid-output handling before looking at results.
Using a biased candidate pool
If one model’s answers are always shown first, first-position selection rate is confounded with candidate identity. Balance the assignment independently of candidate quality.
Overinterpreting confidence fields
A judge’s self-reported confidence is an output, not a calibrated probability. A high-confidence reversal is still a reversal. Use the confidence field for stratified diagnostics unless it has been calibrated against an external reference.
Assuming order swaps solve every evaluator problem
The protocol addresses a specific threat: dependence on display order. It does not detect factual errors, rubric omissions, verbosity preferences, domain blind spots, contamination, prompt sensitivity, or correlated errors between judge and candidate models.
A report format readers can audit
Publish enough information for another engineer to understand what was measured without exposing private prompts, personal data, secrets, or proprietary answer text. A compact report can include:
Evaluation:
task_families: 4
attempted_pairs: 800
pairs_with_two_valid_runs: 776
assignment:
model-x-first: 400
model-y-first: 400
stable_pairs: 702
disputed_pairs: 74
direct_ties: 0
invalid_pairs: 24
Metrics:
valid_pair_rate: 776 / 800
flip_rate: 74 / 776
first_position_rate: report numerator / denominator
stable_win_rate:
model-x: report wins / all attempted valid pairs
model-y: report wins / all attempted valid pairs
Configuration:
judge_model: exact provider model identifier
rubric_version: exact version
sampling: exact supported settings
parser_version: exact code revision
interval_method: exact method and parameters
The numbers in this block are illustrative placeholders only. Replace them with measured values from your own run; do not copy them into a result section. The important property is the separation of attempted, valid, stable, disputed, direct-tie, and invalid records.
Interpreting the outcome
There is no universal flip-rate threshold at which an evaluator becomes acceptable. The tolerance depends on the decision being made. A small order effect may be material when two models are close and the ranking will trigger a release decision. A larger effect may be tolerable for exploratory triage if every conclusion is labeled provisional.
Compare the measured order sensitivity with the margin you are trying to claim. If candidate A wins only slightly more stable pairs than candidate B, but the disputed-pair rate is large, the honest conclusion is that the comparison is unresolved. More judge calls do not automatically fix a systematic protocol flaw.
A good operational rule is to gate claims on stability: publish a candidate ranking only when the stable evidence is sufficient for the decision, the disputed fraction is visible, and the result survives the predefined checks. Otherwise, report a tie or collect better evidence.
Limitations and extensions
The paired swap design controls one variable at a time. It does not establish that the judge’s preferences match human preferences. Human adjudication on a sampled set remains useful for checking validity, while the swap harness checks order sensitivity.
For tasks with more than two candidates, pairwise comparisons multiply quickly. You can use a tournament or sampled pair design, but define how disputed pairs affect the final ranking. A ranking algorithm that discards ties may reintroduce overconfidence downstream.
Position can also operate at more than one level. The judge may prefer the first answer, the first explanation, the first criterion mentioned, or the first tool result in a longer context. If the real system has multiple ordered components, design additional permutations rather than assuming a two-answer swap captures every order effect.
Finally, provider-side nondeterminism can produce different decisions even when order is unchanged. If that matters, add repeated same-order runs and estimate stochastic variability separately. Do not label every change across requests a position effect.
Takeaway
To measure and reduce position bias in LLM-as-a-Judge, make answer order an explicit experimental factor. Run both orders, preserve stable candidate IDs, parse strictly, join the paired runs, and count a disagreement as a disputed tie. Report invalid outputs and uncertainty instead of hiding them inside a single win rate.
The resulting ranking may contain fewer decisive wins. That is a feature: the evaluation now distinguishes evidence of quality from evidence that the judge changed its mind when the layout changed.