Langfuse launches AI Gateway Learn more
DocsLLM-as-a-Judge

LLM-as-a-Judge

LLM-as-a-Judge is an evaluation methodology where an LLM is used to assess the quality of outputs produced by another LLM application. Instead of relying solely on human reviewers or simple heuristic metrics, you prompt a capable model (the "judge") to score and reason about application outputs against defined criteria.

This approach has become one of the most popular methods for evaluating LLM applications because it combines the nuance of human judgment with the scalability of automated evaluation.

To score live production traces with an evaluator and a rule, start with Evaluate Production Traffic.

Evaluators > “New evaluator” > template “Classify Input Topic” (LLM-as-a-judge). Filter the sample observations to the support chatbot, map the {{input}} variable to payload.message under “Map variables to data”, run the judge on one sample to see its score and reasoning, then click “Create evaluator” and confirm the rule in the “Evaluator saved” dialog.

How LLM-as-a-Judge works

The core idea is straightforward: present an LLM with the input, the application's output, and a scoring rubric, then ask it to evaluate the output. The judge model produces a score along with reasoning explaining its assessment.

A typical LLM-as-a-Judge prompt includes:

  1. Evaluation criteria — a rubric defining what "good" looks like (e.g., "Score 1 if the answer is factually incorrect, 5 if fully accurate and well-sourced")
  2. Input context — the original user query or prompt
  3. Output to evaluate — the application's response
  4. Optional reference — ground truth or expected output for comparison

The judge model then returns a structured score and reasoning that can be tracked, aggregated, and analyzed over time. In Langfuse, that score can be numeric, categorical, or boolean. Use numeric scores for continuous judgments like helpfulness from 0 to 1. Use categorical scores when you want explicit labels such as correct, partially_correct, or incorrect. Use boolean scores for binary decisions where the outcome is true or false, such as whether a user is disagreeing with the assistant, whether a request is out-of-scope, or whether an answer violates policy. For more production-monitoring examples, see LLM-as-a-Judge for Production Monitoring.

Why use LLM-as-a-Judge?

  • Scalable: Judge thousands of outputs quickly versus human annotators.
  • Human‑like: Captures nuance (e.g. helpfulness, toxicity, relevance) better than simple metrics, especially when rubric‑guided.
  • Repeatable: With a fixed rubric, you can rerun the same prompts to get consistent scores.

A judge is a prompt you wrote, so check that it scores cases the way your reviewers would before you rely on it: calibrate it against labeled examples, or compare its scores with human annotation scores on the same data in Score Analytics.

Evaluation targets

Which data do you want to evaluate?
Live production data
Score real traffic as it arrives
Offline experiment data
Test changes before you ship
Which scope to evaluate?
Trace
All LLM calls in a trace, read as trace messages
Observation
One operation, such as an LLM call, retrieval, or tool call

See Evaluation targets for how each target works.

Set up step-by-step

Set up an LLM connection

To use an LLM-as-a-Judge evaluator, you need an LLM connection. Evaluators use the project default model unless you select a dedicated model for an evaluator. When you update the project default model, every evaluator that uses it runs with the new model.

Create an LLM-as-a-Judge evaluator

Go to the Evaluators page and click New evaluator. Under Start from scratch, choose LLM-as-a-judge to start with a blank prompt, or select a template provided by Langfuse. A template prepopulates a new evaluator that you can edit without changing the original.

Evaluators page with the New evaluator button

Define the evaluator

An evaluator defines how data is scored: its judge prompt, model, score definition, and default variable mappings. Rules select the incoming observations or traces on which it runs.

  1. Select the model to use: the project default model or a dedicated model for this evaluator.
  2. Write or edit the evaluation prompt with {{variables}} for the data the judge needs, such as {{input}}, {{output}}, or {{ground_truth}}. See Judge prompt for prompt roles and media.
  3. Choose a score type: Numeric for values such as helpfulness from 0 to 1, Categorical for labels, or Boolean for true / false decisions. For Categorical scores, define the allowed categories. You can allow multiple matches when more than one category may apply.

Choose the scope

On the right, under Evaluate, choose whether the evaluator scores single observations or whole traces, then filter to representative samples.

Filter observations by type, name, metadata, or trace attributes such as tags. An observation evaluator sees only the matched observation, not its sibling or child observations. To score a whole trace, choose Traces, or filter on Is Root Observation and record the trace's overall input and output on the root observation.

Filter traces by trace attributes such as trace name, user ID, session ID, or tags, or by observation attributes such as name, type, model, or metadata. Langfuse checks the filters against each observation in the trace. A trace matches if at least one observation matches all filters, so Name = guardrail with Provided Model Name = gpt-5 matches only traces whose guardrail step itself used gpt-5.

A trace evaluator reads the trace's messages, not only the observation that matched. An observation rule scores each matching observation, while a trace rule scores the whole trace once it stops receiving observations, however many of its observations match.

Map variables

Map each prompt variable by clicking the data you want to use.

Select an observation's input, output, metadata, or tool calls. If you plan to use the evaluator in prompt experiments, also map Expected Output and Experiment Item Metadata.

Map each variable to the trace's messages. A blank evaluator starts with a {{messages}} variable that already reads them. If the trace has several threads, see Multi-threaded agents.

Test the evaluator

Select a sample and run the evaluator. Inspect the score and reasoning, then iterate on the model, prompt, score definition, or mappings until the result is useful.

Testing an LLM-as-a-Judge evaluator with sample observations

The sample shows the trace's messages, the same data the evaluator reads. A trace without messages shows This trace cannot be evaluated; see Why does my trace have no messages?

Save the evaluator

After saving, you can:

  • Create a rule from the filters you used to select test samples, or attach the evaluator to an existing rule to run it on incoming observations or traces. The rule uses the scope you tested with, and the scope is fixed after creation.
  • Continue without a rule. Observation evaluators also work in batch evaluation and prompt experiments.

✨ Done! You have created an evaluator, tested it on sample data, and can run it online with a rule.

Need deterministic custom logic? Use code evaluators or ingest scores from an external evaluation pipeline. Need a typed verdict (label, rubric level, or yes/no)? Use a decision-model evaluator.

Deep dive

Judge prompt

Prompt roles

A judge prompt is a sequence of turns, each with a role, that Langfuse sends to the LLM-as-a-Judge model in order. The turns belong to the evaluator itself; data from the scored observation or trace reaches the judge only through mapped {{variables}}. You do not need every role; a single User turn is enough for a simple evaluator.

RoleWhen to use itExample
SystemSet stable evaluator instructions, its rubric, and constraints that apply to every case. A System turn must come first.You are a strict evaluator. Check whether the answer is grounded.
UserProvide the evaluation task and changing data through mapped variables.Evaluate {{output}} against {{ground_truth}}.
AssistantAdd a few-shot example of how the LLM-as-a-Judge evaluator should respond, or an earlier reply before a follow-up User turn.The answer is not grounded because it contradicts the reference text.

Multi-modal evaluation

LLM-as-a-Judge evaluators can score observations that contain images, audio, documents, and other media. Add a variable such as {{input}} or {{output}} to the evaluator prompt, then map it to an observation field that contains Langfuse media. Langfuse resolves the media reference and sends the attachment to the LLM-as-a-Judge model together with the surrounding text.

For example, use multi-modal evaluators to:

  • Compare an image description with the source image.
  • Evaluate a voice agent response against the original audio.
  • Check whether an answer is grounded in an attached PDF.

The selected LLM-as-a-Judge model and provider must support the media type. Langfuse returns an evaluator error if the media cannot be sent to that model. Self-hosters can configure media delivery and attachment size limits with the LANGFUSE_EVALUATOR_MEDIA_* environment variables.

Multi-threaded agents

Observation evaluators work the same in single-threaded and multi-threaded applications. Each one scores a single step within the trace, such as one sub-agent's LLM call, so you set it up the same way however complex the agent is. Trace evaluators read every thread in the trace, in the order the threads started, so the first thread can be a guardrail or sub-agent rather than the main agent's thread.

A trace variable reads the first thread by default. To evaluate another thread, open the variable's mapping and choose an entry under Threads:

  • [0], [1], [2], and so on: one thread, counted from [0] in the order the threads started.
  • [*]: every thread.
  • last: the last thread.

This trip-planner trace has three threads:

LLM-as-a-Judge Map variables step with the Threads list expanded. The entries [0], [1], and [2] point to threads 1.1, 1.2, and 1.3 of a trip-planner trace.

  • [0] is thread 1.1, a guardrail call that checks the user's request and returns {"intent": "plan_trip", "budget_usd": 2000}.
  • [1] is thread 1.2, the main agent's work. It calls tools such as search_activities, loadSkill, and get_restaurants, then answers.
  • [2] is thread 1.3, a sub-agent that the main agent spawned to draft the day-by-day itinerary.

The default mapping, $[0].messages, scores the guardrail call. To score the main agent's answer instead, expand [1] and press Use on messages, which maps the variable to $[1].messages.

The trace preview first shows only the top-level threads. Thread 1.3 is nested under the main agent, so the preview hides it behind 1 nested thread hidden until you click Show. The evaluator still reads it as [2].

Trace preview with 1 nested thread hidden above threads 1.1 and 1.2

See Multi-threaded applications for how threads are built.

Where evaluators run

LLM-as-a-Judge evaluators are executed by the Langfuse worker: it picks up each matching observation or trace from a queue, renders the evaluation prompt, calls the model through the project's LLM connection, and writes the resulting score back. Nothing runs inside your application or in the browser.

For self-hosted deployments this means the worker container — not the web container and not your instrumented application — needs network egress to the LLM provider or gateway configured in the LLM connection, and the SSRF allowlist variables apply to that call. Scale the LLM-as-a-Judge execution queue with LANGFUSE_LLM_AS_JUDGE_EXECUTION_WORKER_CONCURRENCY (default 5); the legacy evaluation queue uses LANGFUSE_EVAL_EXECUTION_WORKER_CONCURRENCY. On Langfuse Cloud, evaluators run in Langfuse's infrastructure. Code evaluators use a separate worker queue and sandbox.

Programmatic setup via API

Beyond the UI, you can set up and manage LLM-as-a-Judge evaluation programmatically through the public API. This is useful for version-controlling your evaluation setup, replicating it across projects, or automating rollouts from a deployment pipeline.

The setup is split into two resources:

  • Evaluators define how to score data: the judge prompt, its {{variables}}, default variable mappings, the structured output definition (numeric, boolean, or categorical), and the optional model configuration. Each evaluator has a stable ID. Updating its definition creates a new version, and active rules automatically use the latest version.
  • Evaluation rules define which live observations are evaluated: filters, sampling rate, and one or more evaluator assignments. An assignment can use the evaluator's default mapping or override it for that rule. The tool_calls mapping source is available for observation data.

A typical flow is to create an evaluator, read back its stable ID, variables, and output definition, then create a rule and attach one or more evaluators to it.

The endpoints are designed to be explored and consumed by coding agents. The recommended way to set up evaluators programmatically is to point an agent at the API reference and have it create the evaluators and wire up the evaluation rules for you.

Observation evaluation rules support a boolean isRootObservation filter with the = and <> operators. To target logical roots, include this filter in the rule:

{
  "type": "boolean",
  "column": "isRootObservation",
  "operator": "=",
  "value": true
}

See the stable Evaluators and Evaluation Rules API reference for the full request and response schemas.

Advanced topics

Advanced score configuration

In Advanced, use the score description and score reasoning fields to give the model more detail about the structured output it should return. This helps the judge return the intended score and explanation.

Backfill historical observation scores

Use batch evaluation to run an LLM-as-a-Judge evaluator on selected historical observations.

Debug LLM-as-a-Judge executions

Every LLM-as-a-Judge evaluator execution creates a full trace, giving you complete visibility into the evaluation process. This allows you to debug prompt issues, inspect model responses, monitor token usage, and trace evaluation history.

You can show the LLM-as-a-Judge execution traces by filtering for the environment langfuse-llm-as-a-judge in the tracing table:

Tracing table filtered to langfuse-llm-as-a-judge
environment

LLM-as-a-Judge Execution Status
  • Completed: Evaluation finished successfully.
  • Error: Evaluation failed and will not be retried automatically (click execution trace ID for details).
  • Delayed: Evaluation encountered a retryable provider error, such as a rate limit, and is waiting for a scheduled retry. See retry timing.
  • Pending: Evaluation is queued and waiting to run.

Evaluator not running

If an evaluator produces no scores, see Why is my observation-level evaluator not executing? or Why is my trace evaluator not running? for common causes and solutions.

"Model configuration not valid for evaluation"

When you save an LLM-as-a-Judge evaluator, Langfuse sends one short test request to the selected model using the evaluator's structured output definition (the score type you chose). If that request fails, saving is blocked with Model configuration not valid for evaluation. followed by the error the provider returned. Typical causes:

  • The model or the proxy in front of it does not support structured outputs (JSON schema). Provider errors that mention response_format usually point to this. Choose a model that supports structured output, or route to the provider directly instead of through a proxy that strips the parameter.
  • The model name does not exist at the provider, or the API key or base URL of the LLM Connection is wrong. The provider's error text names the exact problem.

Fix the connection or pick a different model, then save again. The same check runs when you change the model of an existing evaluator.

Rate limits and retries

When the judge's LLM provider returns a retryable error, such as a rate-limit HTTP 429 from Azure OpenAI, Langfuse schedules another attempt on the worker queue. By default, it allows up to four queued retries in addition to the initial attempt, spread across a 120-minute retry window. Each attempt sends at most one request to the provider.

The nominal retry targets are approximately 5, 43, 82, and 120 minutes into that window. These are elapsed times, not delays to add after each failure. The targets are evenly spaced after the first five-minute target; the queue does not use exponential backoff for this schedule. Each scheduled delay has up to ±20% jitter, capped at the remaining time in the window.

A rate-limit 429 also pauses that model on the LLM connection for every evaluation that uses it, for as long as the provider's retry-after header asks (between 5 seconds and 5 minutes, 60 seconds if the header is missing). An attempt during the pause fails without calling the provider and counts toward the retry limit. A retry after a rate limit runs no earlier than the end of the pause, even if its scheduled target is sooner.

The retry window starts at the evaluation job's creation time plus its configured initial evaluation delay. Queue wait time consumes that window, so these times are approximate and fewer than four retries may be scheduled. A queued retry can execute after the window ends. After a failed attempt, Langfuse sets the execution to Error if the retry count or time budget is exhausted. Permanent credential, billing, or model errors do not follow this schedule and can pause the evaluator; a 429 with insufficient_quota is one such terminal error.

Self-hosters can change the retry count with LANGFUSE_LLM_AS_JUDGE_QUEUE_RETRY_MAX_ATTEMPTS and the window with LANGFUSE_LLM_AS_JUDGE_QUEUE_RETRY_MAX_AGE_SECONDS on the worker. See retry configuration for defaults and units. These are deployment settings, not per-project controls in Langfuse Cloud.

Langfuse does not provide a requests-per-minute limit or a time-of-day execution schedule for managed evaluators. Use rule filters and sampling to reduce the volume evaluated. Self-hosted worker concurrency controls simultaneous executions; it does not enforce a per-minute rate.

Find and rerun failed evaluations

  1. On the Evaluators page, open the evaluator's actions menu and choose View executions. You can also filter the Traces table to the environment langfuse-llm-as-a-judge. Adjust the time range to include the failed attempts.
  2. Inspect executions with errors and open their traces to read the provider error and rendered prompt. A failed attempt may still have a scheduled retry; check whether the evaluation is Delayed or has reached terminal Error before rerunning it.
  3. Identify the original application data from the execution trace's target_trace_id and, for observation-level evaluation, target_observation_id metadata. Resolve the provider quota or configuration problem first.
  4. Open the evaluator and check for a blocked status or banner. After fixing the provider problem, reactivate the evaluator if it was paused so it can resume scoring live traffic. See LLM connection troubleshooting.
  5. Return to the original application traces in the Traces table, select the affected rows, and choose Actions → Evaluate. Select the evaluator to run a new batch evaluation on those observations. For a broader historical backfill, use Also run on past observations.

Rerun the original application data, rather than the judge's execution traces. Batch evaluation creates new evaluations and can also score observations that already have scores; select the affected data carefully.

FAQ

What is LLM-as-a-Judge evaluation?

LLM-as-a-Judge is an evaluation methodology where a large language model (the "judge") assesses the quality of outputs from another LLM application. The judge model is given the input, the application's output, and a scoring rubric, then produces a score with reasoning. It's one of the most popular approaches for evaluating LLM applications because it combines human-like nuance with automated scalability.

How accurate is LLM-as-a-Judge compared to human evaluation?

Research shows that strong LLM judges (such as GPT-5 class models) achieve 80-90% agreement with human evaluators on many quality dimensions, which is comparable to inter-annotator agreement between humans. Accuracy improves significantly with well-designed rubrics and clear evaluation criteria. For best results, calibrate your LLM-as-a-Judge setup against a small set of human-annotated examples, and use Score Analytics to measure agreement between judge and human scores.

What models work best as LLM judges?

The most capable models generally produce the best evaluations. Models with strong instruction-following and reasoning capabilities (such as GPT-4o, Claude Sonnet, or Gemini Pro) are commonly used. The judge model should support structured output so scores can be reliably parsed. In Langfuse, you configure the judge model via LLM Connections.

How much does LLM-as-a-Judge cost?

Cost depends on the judge model and the size of the inputs being evaluated. A typical evaluation costs $0.01-0.10 per assessment. You can manage costs by: (1) using sampling to evaluate a percentage of traces, (2) targeting specific observations instead of full traces, and (3) choosing cost-effective judge models for simpler evaluations.

Can I use LLM-as-a-Judge for RAG evaluation?

Yes. LLM-as-a-Judge is particularly effective for RAG pipelines. You can evaluate faithfulness (is the answer grounded in the retrieved context?), relevance (does the answer address the question?), and completeness (does the answer cover all relevant information?). Langfuse also integrates with RAGAS for specialized RAG evaluation metrics.

GitHub Discussions


Was this page helpful?

Last updated on