Zero Labs
Industry News / AI

LLM-as-a-Judge: Building LLM-Based Evaluation Pipelines for AI Applications

Source · Towards AI By Divakar Ungatla

From the publisher’s feed, collected in the ZeroLabs newsroom.

AI Engineering FundamentalsAI Evaluation · Part 5← Part 4📦 Complete CodeThe complete implementation used in this article is available in the companion Wayfinder repository on GitHub. To follow along with the exact code and examples from this article, check out the v0.4.0 release.View the complete code on GitHubIn the previous article, we explored Human Evaluation and how human reviewers can assess AI application quality using structured evaluation criteria.Human evaluation solves an important problem - it allows us to measure qualities that are difficult to express as deterministic rules, such as helpfulness, relevance, completeness and groundedness.However human evaluation has a practical limitation — it does not scale.As AI application grows, the number of interactions increases rapidly. Reviewing every response manually becomes expensive, time-consuming, and difficult to maintain.This raises an important question:Can we automate the evaluation process while maintaining the quality of human judgment ?This is where LLM-as-a-Judge comes in.Instead of relying entirely on human reviewers, we can use another large language model to evaluate AI-generated responses against predefined evaluation criteria.At a high level, LLM-as-a-Judge introduces another LLM into the evaluation pipeline. The application LLM generates the response, while the judge LLM evaluates that response against predefined criteria.In this article, we will explore how LLM-as-a-Judge works, build an evaluation pipeline for an AI application, and see how evaluation platforms like LangSmith help run and track these evaluations at scale.How Does LLM-as-a-Judge Work?The key idea behind LLM-as-a-Judge is simple — instead of asking a language model only to generate responses, we introduce another language model whose responsibility is to evaluate those responses.In an AI application, there are now two distinct roles:Application LLM — generates the response for the user.Judge LLM — evaluates the generated response against predefined evaluation criteria.The application LLM tries to solve the user’s request. The judge LLM does not solve the request again; it reviews whether the response produced by the application meets the expected quality standards.Let’s understand this using Wayfinder, our flight search AI application.A user asks:Find the cheapest flight from Bangalore to Tokyo tomorrow.The Wayfinder agent processes the request, searches available flight data, and generates a response:The cheapest flight is Air India AI302 at ₹410.Now the judge LLM evaluates this response.The judge receives:User Query:Find the cheapest flight from Bangalore to Tokyo tomorrow.Application Response:The cheapest flight is Air India AI302 at ₹410.Retrieved Context:Available flight information returned by the search tool.Evaluation Criteria:- Helpfulness- Relevance- Completeness- Groundedness- Instruction FollowingThe judge is not checking whether the response matches a hardcoded expected answer. Instead, it evaluates whether the response is correct, useful, and supported by the available context.The output is an evaluation result:Helpfulness: 5/5Groundedness: 5/5Instruction Following: 5/5Explanation:The response correctly identifies the cheapest flightand the information is supported by the retrieved flight data.Designing Evaluation CriteriaAn LLM judge is only as effective as the criteria it uses to evaluate responses.Just like human reviewers need a clear rubric to evaluate AI outputs consistently, an LLM judge also needs predefined evaluation criteria that describe what a good response looks like.For Wayfinder, we use the same evaluation dimensions introduced in human evaluation:Helpfulness — Does the response help the user complete their task?Relevance — Does the response address the user’s actual request?Completeness — Does the response include all important information needed by the user?Groundedness — Is the response supported by the available context?Instruction Following — Does the response satisfy the user’s requirements and constraints?These criteria form the evaluation rubric that defines how the judge LLM should assess response quality.For example, instead of asking:Is this response good?the judge receives specific criteria:Evaluate this response for:- Helpfulness- Groundedness- Instruction FollowingThis makes evaluations more consistent and repeatable across different responses.In the next section, we will see how these criteria are translated into an LLM-as-a-Judge implementation and how the evaluator produces structured scores and explanations.Building the LLM-as-a-Judge EvaluatorNow that we have defined our evaluation criteria, the next step is to build an evaluator that can apply this rubric to AI-generated responses.An LLM-as-a-Judge pipeline starts with an evaluation dataset.The complete code is here — Wayfinder.Creating an Evaluation DatasetAn evaluation dataset contains representative user scenarios that we want our AI application to handle.Each evaluation sample contains:Input — the user query sent to the applicationExpected behavior — describes the quality expectations that guide evaluationMetadata — information used to organize and analyze resultsFor Wayfinder, our dataset contains scenarios such as:{ "inputs": { "query": "Find the cheapest flight from Bangalore to Tokyo tomorrow." }, "outputs": { "expected_behavior": "Recommend the retrieved flight with the lowest price without inventing information." }, "metadata": { "category": "cheapest" }}The important thing is that the dataset does not contain a fixed expected answer. Instead, it describes the expected behavior of the application.During evaluation, each dataset sample is executed against the AI application.Designing the Judge PromptThe quality of an LLM-as-a-Judge system depends heavily on how the judge prompt is designed.A good judge prompt should clearly define:RoleTell the model that it is an evaluator, not a response generator.Evaluation CriteriaDefine what dimensions should be scored.Evaluation ContextProvide the information needed to judge the response.Output FormatRequire structured scores and explanations.For Wayfinder, the judge prompt follows this pattern:You are an expert evaluator assessing the quality of an AI assistant response.You will be given:- The user's original query.- The expected behavior: a description of what a good assistant response should do for this query.- The assistant's actual response.- The flight data retrieved by the search tool before the response was generated.Your task is to evaluate the assistant's response against each of the following criteria.Evaluation criteria and rubric:{criteria_block}Instructions:- "Expected behavior" describes what the application was expected to do for this sample. It is not a model answer. Use it to understand the intent of the query.- Evaluate the response against each criterion independently.- When evaluating Groundedness, cross-reference the response against the retrieved flight data.- Do not invent facts that are not present in the supplied context.- Score every criterion from 1 to 5 using the rubric above.- Provide a concise explanation for every criterion score.- Provide an overall score from 1 to 5 that reflects your holistic judgment. Do not calculate the overall score as an average of the criteria scores.- Provide a concise overall explanation."""User Query:{query}Application Response:{response}Retrieved Context:{context}Provide a score from 1-5 for each criterionand explain your reasoning.The judge is not asked to generate a better response. Its only responsibility is to evaluate the response it receives.Generating Structured Evaluation ResultsFree-form evaluation responses from the judge are difficult to analyze automatically.Instead, the evaluator asks the LLM Judge to return structured output. In our implementation, we enforce a predefined response schema so every evaluation produces a consistent format.The schema contains:A score for each evaluation criterionA concise explanation for each scoreAn overall score and explanationExample:{ "criteria_scores": [ { "criterion": "Helpfulness", "score": 5, "explanation": "The response directly answers the user's request." }, { "criterion": "Groundedness", "score": 5, "explanation": "The response is supported by the provided context." }, { "criterion": "Instruction Following", "score": 5, "explanation": "The response satisfies the user's requirements." } ], "overall_score": 5}Implementing the JudgeWith the evaluation dataset, criteria, judge prompt, and structured output format in place, we can now implement the LLM-as-a-Judge evaluator.The evaluator acts as a reusable component that takes an AI application’s output and evaluates it using the predefined rubric.At a high level, the judge performs four steps:Build the evaluation contextSend the evaluation request to the judge LLMParse the structured responseReturn the evaluation resultThe evaluator receives:User QueryApplication ResponseExpected BehaviorRetrieved ContextEvaluation Criteriaand produces:Criterion Scores+Explanations+Overall AssessmentThe application code exposes a simple interface:result = judge.evaluate( query=query, expected_behavior=expected_behavior, response=response, retrieved_flights=retrieved_context)Internally, the evaluator builds the judge prompt:messages = [ { "role": "system", "content": judge_instructions }, { "role": "user", "content": evaluation_input }]The system prompt defines the judge’s role, evaluation criteria and scoring guidelines. The user message provides the specific evaluation sample, including the query, response and supporting context.The LLM response is then parsed into the structured evaluation model:JudgeResult( criteria_scores=[ CriterionScore( criterion="Groundedness", score=5, explanation="The response is supported by the retrieved context." ) ], overall_score=5, overall_explanation="The response satisfies the user's request.")Keeping the judge as a separate component makes it reusable. The same evaluator can be applied to different versions of an AI application using the same evaluation dataset and criteria.This allows teams to measure whether changes actually improve the system:Did a new prompt improve response quality?Did a model upgrade produce better responses?Did a retrieval change improve groundedness?Instead of manually reviewing responses after every change, teams can run repeatable evaluations and compare results across versions.Running the LLM-as-a-Judge EvaluationThe complete implementation used throughout this article is available in the companion GitHub repository. To follow along with exactly the same code shown in this article, check out the v0.4.0 release. This ensures the code, commands, and screenshots remain consistent over time.To run the examples locally, clone the repository and checkout the release containing the LLM-as-a-Judge implementation.git clone https://github.com/DivakarUngatla/wayfinder.gitcd wayfindergit checkout v0.4.0-llm-judgeInstall the project dependencies:uv syncBefore running the evaluation, configure the required environment variables.Create a .env file:cp .env.example .envAdd your OpenAI API key:OPENAI_API_KEY=For LangSmith experiments later in this article, also configure:LANGSMITH_API_KEY=LANGSMITH_TRACING=trueRunning the EvaluationThe LLM-as-a-Judge evaluator uses the evaluation dataset created earlier. The complete dataset containing evaluation scenarios, expected behavior and metadata is available in the companion repository:examples/llm_judge_evaluation/llm_judge_evaluation_dataset.jsonlThe evaluator loads each sample from this dataset, runs the application, and passes the generated response to the LLM judge for evaluation.uv run examples/llm_judge_evaluation/local_evaluation.pyFor each evaluation sample, the judge evaluates the generated response against the predefined criteria and returns structured scores along with explanations.For example, consider the arrival-time constraint scenario:User Query:Which flight from Bangalore to Tokyo arrives before 8 PM?The judge evaluates the response across criteria that is provided to it.After evaluating all samples in the dataset, the pipeline generates an overall evaluation summary.While this run completed successfully, evaluation becomes especially valuable when it detects regressions after application changes.Detecting Regressions with LLM-as-a-JudgeAfter establishing the baseline evaluation, we can introduce a controlled change to simulate a regression.In a real AI system, changes to prompts, models or retrieval logic can unintentionally affect response quality.For this example, let us temporarily modify the response-generation prompt. Change the below line in theIf the user asks for cheapest, select the flight with the lowest price among flights satisfying all constraints.toIf the user asks for cheapest, provide the two cheapest available options.The evaluation dataset remains unchanged. Only the application behavior changes.Running the evaluation again produces something as shown belowThe LLM judge identifies that the response is technically correct but does not fully satisfy the user’s intent.The response identifies the cheapest flight correctly, but it provides an additional flight even though the user requested only the cheapest option.The evaluator detects this through criteria such as:HelpfulnessRelevanceInstruction FollowingThis demonstrates an important advantage of LLM-as-a-Judge: it can evaluate whether a response satisfies the user’s intent, not just whether the output contains valid data.Scaling Evaluations with LangSmithOnce we start running evaluations repeatedly across different application versions, we need a way to track experiments and compare results. Evaluation platforms like LangSmith provide the required infrastructure.The same evaluation dataset used for local evaluation can be uploaded to LangSmith.Uploading the Evaluation DatasetThe evaluation dataset contains:Inputs — user queries sent to the applicationOutputs — expected behavior used by the judgeMetadata — information used to organize evaluation samplesThe dataset used in this article is available in the companion repository.wayfinder_llm_judge_evaluation_v1.jsonlCreate a new dataset and upload the JSONL file.LangSmith automatically detects the fields from the dataset.For Wayfinder:Input field → inputs.queryOutput field → outputs.expected_behaviorMetadata fields → metadata.id, metadata.categoryRunning the EvaluationThe LangSmith evaluation runner uses the same LLM-as-a-Judge evaluator that we built earlier.Run:uv run examples/llm_as_a_judge/langsmith_evaluation.pyThe evaluator executes each dataset example against Wayfinder and sends the generated response to the judge.Once the evaluation completes, click on the langsmith link displayed to view the resultsFor each example, we can inspect:Input queryApplication responseJudge scoresJudge explanationsEvaluation metadataThe important point is that the evaluator itself does not change. The same LLM-as-a-Judge component can run locally or through LangSmith.ConclusionIn this article, we explored LLM-as-a-Judge, an evaluation approach where an LLM acts as an evaluator to assess AI-generated responses against predefined criteria.We built an end-to-end LLM-as-a-Judge evaluation pipeline for an AI-powered flight search application, covering evaluation criteria, judge prompts, structured evaluation results, and running evaluations locally and through LangSmith.Unlike traditional rule-based checks, LLM-as-a-Judge can evaluate whether AI responses satisfy user intent while considering the context available to the application. It provides both scores and explanations, helping teams understand and improve AI application quality.What’s Next?LLM-as-a-Judge enables powerful offline evaluation using curated scenarios. However, offline evaluation only covers predefined cases. Production AI systems also need evaluation approaches that learn from real user interactions and live application behavior.In the next article, we’ll explore Online Evaluation, where we’ll learn how to evaluate AI applications using real-world usage data and feedback signals.AI Evaluation SeriesFollow along as we build a complete AI evaluation toolkit — from deterministic rule-based checks to human evaluation, LLM-as-a-Judge, evaluation datasets, and production-scale evaluation workflows.✅ Part 1: Software Tests vs AI Evals✅ Part 2: Understanding AI Evaluation✅ Part 3: Rule-Based Evaluation✅ Part 4: Human Evaluation✅ Part 5: LLM-as-a-Judge▶️ ⏳ Part 6: Online Evaluation (Coming Soon)⏳ Part 7: Comparing Evaluation Experiments (Coming Soon)LLM-as-a-Judge: Building LLM-Based Evaluation Pipelines for AI Applications was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.