FrontierAI.Engineer
Evaluation, Safety & Guardrails

LLM-as-Judge Evaluation

9 min read

Use a capable model as an automated scorer to evaluate outputs too open-ended for deterministic checks.

Many AI tasks produce outputs that have no single correct answer: summarization, creative writing, conversational responses, code explanations. Deterministic metrics fail here because they cannot capture semantic quality. LLM-as-judge uses a capable model to score outputs according to a rubric, producing scalable automated evaluation for tasks where human grading is too slow or expensive to run continuously.

How it works

You construct a judge prompt that gives the model the original task input, the response being evaluated, and a scoring rubric. The judge model returns a score — numeric, categorical, or a chain-of-thought reasoning trace followed by a final verdict. The most reliable judges reason step by step before committing to a score, which also produces a human-readable explanation for debugging.

JUDGE_PROMPT = """
You are evaluating a customer support response. Score it on the criteria below.
Respond with JSON: {"score": 1-5, "reasoning": "..."}

Criteria:
- Addresses the customer's specific question (1-2 pts)
- Tone is professional and empathetic (1 pt)
- Provides actionable next steps (1-2 pts)

Customer message: {customer_message}
Agent response: {agent_response}
"""

def judge_response(customer_message: str, agent_response: str) -> dict:
    prompt = JUDGE_PROMPT.format(
        customer_message=customer_message,
        agent_response=agent_response,
    )
    result = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": prompt}],
        response_format={"type": "json_object"},
    )
    return json.loads(result.choices[0].message.content)

Prompt patterns for reliability

  • Use a rubric with explicit criteria and point values rather than asking for a free-form quality score
  • Ask for reasoning before the score to reduce position bias and anchoring effects
  • Use pairwise comparison (which of A or B is better?) instead of absolute scoring when the rubric is hard to calibrate
  • Set temperature to 0 for deterministic judgment; run multiple samples if you need variance estimates
  • Include a few-shot example in the judge prompt to anchor the judge to your quality bar

Validating the judge

A judge you haven't validated is a hypothesis, not a metric. Hold out 100 or so examples with human labels and measure agreement between the judge and the human raters. Cohen's kappa or Pearson correlation work well depending on whether the scores are categorical or continuous. Aim for at least 0.7 agreement before treating the judge as production-ready.

Failure modes

LLM judges are susceptible to verbosity bias (longer answers score higher), self-preference bias (a judge from the same provider as the system model tends to favor that style), and sycophancy (scoring positively when the prompt implies the answer is good). Mitigate these by using a different model family for the judge, anonymizing which system produced each response in A/B comparisons, and auditing judge scores periodically against fresh human labels.

warning

Never report LLM-judge scores without stating the judge model and prompt version. A score of 4.2/5 is meaningless without that context, and judge behavior changes with model updates.

note

Pairwise judging (is A better than B?) is typically more reliable than absolute scoring because it removes the difficulty of calibrating an abstract scale. Use it when comparing two prompt variants or model versions.