LLM-as-Judge: Using a Model to Grade Outputs (G-Eval, Arena)
~14 min read
An LLM-as-judge uses a strong model (GPT-4, Claude) to score or compare outputs against a rubric — flexible enough for open-ended tasks where reference metrics fail, but carrying real biases you must design around.
When there's no single gold answer — 'is this a helpful support reply?', 'is this summary faithful?' — reference metrics fall apart. LLM-as-judge fills the gap: you ask a strong LLM to evaluate the output, guided by a rubric you write. It's flexible, fast, and scales far better than human review, which is why frameworks like G-Eval and the Arena-as-a-judge pattern have become standard evaluation tools.
There are two common shapes. Direct scoring (the G-Eval style) hands the judge one output plus a rubric and asks for a score, often with chain-of-thought reasoning first and a structured score at the end ('rate faithfulness 1-5, explaining your reasoning'). Pairwise comparison (the Arena style) shows the judge two outputs — A and B — for the same input and asks which is better. Pairwise tends to be more reliable than absolute scoring because 'which of these two is better' is an easier, more consistent judgment for a model than 'assign an absolute number,' and it's the basis of Chatbot-Arena-style leaderboards.
The catch is that LLM judges have systematic biases you must design around:
- Position bias: judges often favor whichever answer is shown first (or sometimes last). Mitigate by running each pair in both orders (A,B and B,A) and only counting a win if it's consistent.
- Verbosity/length bias: judges tend to prefer longer, more elaborate answers even when a concise one is better. Your rubric should explicitly reward correctness and concision.
- Self-preference bias: a judge may rate outputs from its own model family more highly. Prefer a judge from a different family than the model under test where possible.
- Sensitivity to prompt wording: small rubric changes swing scores, so version and freeze your judge prompt like code.
Good practice: use a strong judge model, give it a clear rubric with explicit criteria and a fixed output format, ask for reasoning before the verdict, swap positions to cancel position bias, and — critically — calibrate the judge against a sample of human labels so you know how much to trust it. LLM-as-judge is powerful but it's still a model with opinions; treat its scores as a well-correlated signal, not ground truth.
💻 Code example
# A pairwise LLM-as-judge with position-bias mitigation:
# run both orders and only count a consistent win.
import json
JUDGE_PROMPT = """You are an impartial evaluator. Given a user question
and two answers (A and B), decide which answer is more helpful, correct,
and concise. Reason briefly, then output JSON: {{"winner": "A"|"B"|"tie"}}.
Question: {q}
Answer A:
{a}
Answer B:
{b}"""
def judge_once(client, q, a, b) -> str:
msg = client.chat(JUDGE_PROMPT.format(q=q, a=a, b=b)) # your LLM call
return json.loads(msg)["winner"]
def judge_pairwise(client, q, ans_a, ans_b) -> str:
"""Swap positions to cancel position bias; require a consistent winner."""
first = judge_once(client, q, ans_a, ans_b) # A shown first
second = judge_once(client, q, ans_b, ans_a) # positions swapped
# In the swapped run, 'A' now refers to ans_b, so remap:
second_remapped = {"A": "B", "B": "A", "tie": "tie"}[second]
if first == second_remapped:
return first # consistent across both orders
return "tie" # order-dependent -> treat as inconclusive
# winner = judge_pairwise(client, question, model_output, baseline_output)
💬 Deep Dive with AI
Key points
- •LLM-as-judge uses a strong model + a rubric to evaluate open-ended outputs where reference metrics (BLEU/ROUGE) fail
- •Two shapes: direct scoring (G-Eval style, score one output against a rubric) and pairwise comparison (Arena style, pick the better of two)
- •Pairwise is usually more reliable than absolute scoring because 'which is better' is an easier, more consistent judgment for a model
- •Design around known biases: position bias (swap orders), verbosity bias (reward concision), self-preference (use a different-family judge)
- •Calibrate the judge against human labels and freeze/version the judge prompt — its scores are a correlated signal, not ground truth