Sub topic 9
Using an LLM as a judge, and where it goes wrong
This chapter assumes you have read the chapters on faithfulness and claim-level scoring. You should be comfortable reading Python and know that a verifier is a function that takes a claim and a context and returns True or False.
Why use a judge
The claim-level scorer from the previous chapter needs a function is_supported(claim, context). Substring matching is too weak, because paraphrases fail it. Human review is accurate but slow and costly. An LLM judge is a model prompted to make that decision for you. It handles paraphrase, runs in seconds, and scales to thousands of answers.
A judge is itself a measuring instrument, and it has errors. Treat its output as an estimate until you have checked it (the next-but-one chapter covers checking).
A judge you can plug in
The function below matches the is_supported signature from the claim-level scorer. The call_llm argument is any function that sends a prompt string to your model and returns its text reply.
JUDGE_PROMPT = """You are checking whether a claim is supported by a context.
Use only the context. Do not use outside knowledge.
Context:
{context}
Claim:
{claim}
Reply with exactly one word: SUPPORTED or UNSUPPORTED."""
def llm_is_supported(claim, context, call_llm):
prompt = JUDGE_PROMPT.format(context=context, claim=claim)
reply = call_llm(prompt).strip().upper()
if reply == "SUPPORTED":
return True
if reply == "UNSUPPORTED":
return False
raise ValueError(f"Unparseable judge reply: {reply!r}")
# Stub model so the example runs without an API key.
def fake_llm(prompt):
return "SUPPORTED" if "24 months" in prompt.split("Claim:")[1] else "UNSUPPORTED"
context = "The warranty lasts 24 months. It covers manufacturing defects."
print(llm_is_supported("The warranty lasts 24 months.", context, fake_llm))
print(llm_is_supported("It covers water damage.", context, fake_llm))Three design choices matter here. The prompt tells the judge to use only the context, because otherwise it may "know" a fact and approve a claim the context never states. The output format is a fixed label, so parsing is strict. The code raises an error on an unexpected reply instead of silently counting it as False, which would bias your scores downward without telling you.
Where judges go wrong
| Bias | What happens | Mitigation |
|---|---|---|
| Verbosity bias | Longer, more detailed answers get higher scores. | Judge short atomic claims, not whole answers. |
| Position bias | In pairwise comparisons, the first (or last) option wins more often. | Run both orders and keep only consistent verdicts. |
| Self-preference | A model rates its own style of output higher. | Use a different model family for judging than for generating. |
| Leniency | The judge accepts claims that are plausible but absent from the context. | Use a strict prompt and test it on known unsupported claims. |
| Prompt sensitivity | Small wording changes shift scores. | Fix the prompt, version it, and re-validate after any edit. |
Reducing noise
Set the temperature to 0 so the same input gives the same verdict as far as possible. Even then, some providers return slightly different outputs across calls. For borderline cases, sample the judge an odd number of times (for example three) and take the majority vote. Log every verdict with the claim and context, so you can read the disagreements later.
Common errors
- Giving the judge the whole answer and asking for a 1 to 10 score. Numeric scales are poorly calibrated. Binary per-claim verdicts are more stable.
- Letting the judge see the reference answer when it should check only against the context. This blends faithfulness with correctness.
- Trusting the judge without any human-labelled check.
Exercise
Your judge model is the same model that generates the RAG answers, and faithfulness scores look unusually high. Name the likely bias and one change that tests it.
Show answer
Self-preference. Rerun the judging with a model from a different family, and compare scores on the same answers. If scores drop noticeably, the original judge was lenient toward its own output. Then confirm which judge is closer to human labels.