home
diamond Go Premium
Data Engineering Path  ·  Data & AI

Chapter 4: Evaluate AI Systems (Practical Tooling)

+-----------------------------------------------------------------------------+
|                          LLM-AS-A-JUDGE EVALUATION                          |
+-----------------------------------------------------------------------------+
|  Question + Context + Candidate Output ---> Frontier Model (GPT-4o)         |
|                                                       |                     |
|                                                       v                     |
|  Output: Structured JSON Score (1-5) + Rigorous Step-by-Step Justification  |
+-----------------------------------------------------------------------------+

The LLM-as-a-Judge Paradigm

Instead of relying solely on expensive human annotators, production teams use a larger, more capable model (the "Judge") to evaluate smaller operational models:

1. Single-Answer Grading

The judge evaluates one output against a strict rubric.

2. Pairwise Comparison (Side-by-Side Arena)

The judge is given two outputs (Model A vs. Model B) blindly and selects the winner to compute Elo ratings.


Implementation: Production Faithfulness Evaluator

from pydantic import BaseModel, Field
from openai import OpenAI

class FaithfulnessVerdict(BaseModel):
    is_faithful: bool = Field(description="True if all claims are backed by context")
    hallucinated_claims: list[str] = Field(description="List of statements unsupported by context")
    confidence_score: float = Field(ge=0.0, le=1.0)
    reasoning: str

def evaluate_faithfulness(question: str, context: str, answer: str) -> FaithfulnessVerdict:
    client = OpenAI()
    prompt = f"""
You are an impartial evaluator auditing an AI assistant for hallucinations.
Verify if the ANSWER contains any factual claims not directly supported by the CONTEXT.

QUESTION: {question}
CONTEXT: {context}
ANSWER: {answer}
"""
    res = client.beta.chat.completions.parse(
        model="gpt-4o",
        response_format=FaithfulnessVerdict,
        messages=[{"role": "user", "content": prompt}],
        temperature=0.0
    )
    return res.choices[0].message.parsed

Avoiding Judge Biases

Chip warns of four prominent biases when using LLM judges:

  1. Position Bias: Models tend to favor the first answer in pairwise evaluations (Mitigation: swap positions and average).
  2. Verbosity Bias: Models favor longer, wordier answers even if they contain fluff (Mitigation: penalize unnecessary word length).
  3. Self-Enhancement Bias: A model (e.g. GPT-4) tends to score its own outputs higher than Claude or Gemini outputs.
Find this content helpful? ☕ Buy me a coffee

Entity Details

Create New Item

help

Submit Technical Query

Have a question or run into an issue? Describe it below, upload an optional screenshot, and our engineering team will answer it!

image Attach image (optional)

Submit Feedback

build Free Developer Utility Free Tool
gavel

Privacy & Legal Disclaimer

1. Client-Side Browser Processing

All utility tools on DeepEngineerHub (including Image to PDF, Text Formatters, JSON Converters, and Encryptors) execute 100% locally within your client browser using WebAssembly and JavaScript. No uploaded images, text, or documents are transmitted, collected, or stored on remote servers.

2. Limitation of Liability ("As-Is" Provision)

Tools and services are provided free of charge for convenience and educational purposes "as-is" without warranties of any kind. DeepEngineerHub shall not be held liable for any data loss, formatting inconsistencies, or indirect damages resulting from tool usage.

3. Open Source & Third-Party Software

Certain utilities utilize open-source client libraries (such as jsPDF, Mermaid.js, Pyodide) licensed under MIT, Apache, or BSD open licenses. All intellectual property remains with their respective copyright holders.