Swap the Answers Before You Trust the Judge
An LLM judge comparing two answers tends to prefer the one it reads first. Implement pairwise(judge, question, a, b), which asks the judge twice with the answers swapped and only declares a win the judge gives in both orders, and tally(judge, battles), which runs a batch. judge(question, first, second) is provided and returns the judge's reply as text.
- Two calls, in this order:
judge(question, a, b), thenjudge(question, b, a). - Reading a reply. The verdict is the last
[[A]],[[B]]or[[C]]in the text, ignoring case and spaces inside the brackets:[[A]]means the answer shown first is better,[[B]]the one shown second,[[C]]a tie. A reply without one (Assistant A is better) has no verdict. pairwisereturns{"winner": w, "verdicts": [v1, v2]}. Each verdict is the answer that call preferred ("a"or"b"),"tie", orNonefor a reply with no verdict.wis"a"or"b"only when both verdicts name it; anything else is"tie".tallytakes battles as(question, model_a, answer_a, model_b, answer_b)and returns{"wins": {model: count}, "ties": n, "consistent": n, "favored_first": n}.winshas every model in the battles, with 0 for one that never won;tiescounts battles whose winner is"tie".consistentcounts battles whose two verdicts are equal and notNone.favored_firstcounts battles where each call picked the answer it showed first.
The catch. In the second call b is shown first, so [[A]] there is a verdict for b. A judge that always replies [[A]] gives verdicts ["a", "b"]: a tie and one more favored_first, not a win for a.