# Judgeval

> Open-source SDK that traces AI agents and scores their behaviour with agent judges

- Category: Evaluation & Production Ops / Observability & LLMOps
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/JudgmentLabs/judgeval
- Website: https://judgmentlabs.ai/
- Canonical page: https://ai-tldr.dev/tools/judgeval/

## In short

Judgeval is the open-source Python SDK from Judgment Labs for improving AI agents once they are in production. It sits in the Observability & LLMOps category of the Evaluation & Production Ops tools and is open-source, written in Python and licensed Apache-2.0. To get started: install Judgeval.

## Overview

Judgeval is the open-source Python SDK from Judgment Labs for improving AI agents once they are in production. Its README describes it as tracing and agent-judge evaluation for LLM-powered applications: you instrument your agent, every run is recorded as a trace, and judges score those traces so you can detect failures, understand what went wrong, and check a fix against real production cases before you ship it.

Tracing is built on OpenTelemetry. You decorate functions with `@Tracer.observe()` and wrap your model client, and Judgeval captures inputs, outputs and LLM token usage as spans under one agent root. Auto-instrumentation covers OpenAI, Anthropic, Google GenAI and Together AI, with framework support for LangGraph, OpenLit and the Claude Agent SDK; the docs list further integrations such as the OpenAI Agents SDK, Google ADK, Vercel AI SDK, LiveKit and Pipecat.

Agent judges are prompt-based scorers you define once and run at scale. Each judge turns a trace into a structured, labelled behaviour, and those behaviours accumulate into a searchable record of how your agent acted. Judges can score live production traffic server-side through online monitoring (with Slack alerts for regressions) or be replayed on historical traces. The traces and judges live in the hosted Judgment platform, so the quickstart needs a Judgment account, API key and organization ID; the platform can also be reached from a CLI, an MCP server and a read-only SQL API in the SDK.

## What it does

- OpenTelemetry-based tracing via `@Tracer.observe()`, capturing inputs, outputs and LLM token usage
- Prompt-based agent judges that turn traces into scored, labelled behaviours
- Online monitoring that scores live production traffic server-side, with Slack alerts
- Replay of judges on historical traces to validate a fix before shipping
- Auto-instrumentation for OpenAI, Anthropic, Google GenAI and Together AI, plus LangGraph, OpenLit and Claude Agent SDK support
- Read-only SQL queries over trace data with `Judgeval.sql()`, plus a companion CLI and MCP server

## Getting started

These steps follow the Judgment docs quickstart: install the SDK, point it at your Judgment project, trace one agent path, then attach a judge in the Judgment app.

1. Install Judgeval

   Install the SDK together with the OpenAI client and python-dotenv used by the example. The docs also ship a TypeScript package installed with `npm install judgeval openai`.

```bash
pip install judgeval openai python-dotenv
```

2. Set your credentials

   Create a Judgment account and project, copy the API key from Settings > Account & API Key, and set it with the organization ID and the exact project name.

```text
JUDGMENT_API_KEY="your_judgment_api_key"
JUDGMENT_ORG_ID="your_organization_id"
JUDGMENT_PROJECT_NAME="your_exact_project_name"
OPENAI_API_KEY="your_openai_api_key"
```

3. Trace one agent path

   Initialise the tracer before creating wrapped clients, put one `agent` span around the user-visible work and let tool and model calls become its children. Run it with `python trace_agent.py`.

```python
import os

from dotenv import load_dotenv
from judgeval import Tracer
from openai import OpenAI

load_dotenv()
Tracer.init(project_name=os.environ["JUDGMENT_PROJECT_NAME"])
openai = Tracer.wrap(OpenAI())

@Tracer.observe(span_type="tool", span_name="retrieve_context")
def retrieve_context(question: str) -> str:
    return f"Reference material relevant to: {question}"

@Tracer.observe(span_type="agent", span_name="run_agent")
def run_agent(question: str) -> str:
    context = retrieve_context(question)
    response = openai.chat.completions.create(
        model="gpt-5.2",
        messages=[{
            "role": "user",
            "content": f"Question: {question}\n\nContext: {context}",
        }],
    )
    return response.choices[0].message.content

if __name__ == "__main__":
    print(run_agent("What is the capital of the United States?"))
    Tracer.shutdown()
```

4. Check the trace

   In your Judgment project open Logs > Traces and the newest `run_agent` trace. It should show one `run_agent` root, a `retrieve_context` tool span and one model span under it, with a completed duration.

5. Create and monitor an agent judge

   Open Judges > New Judge, choose Create manually and Binary, name it `Uses retrieved context` and give it the prompt below. Then use Set up monitoring with Continuous evaluation at 100% sampling, run the agent again, and read the judge's decision and reasoning in the trace's Behaviors panel.

```text
Return true when the agent retrieves context before answering the user.
Return false when it answers without retrieving context.
```

## When to use it

- Tracing a production agent's tool and model calls to find the step where a bad answer started
- Continuously scoring live agent traffic with a judge and getting a Slack alert when a behaviour regresses
- Replaying a judge on historical traces to confirm a prompt or code fix before shipping it
- Querying trace history with read-only SQL from a script, the CLI or a coding agent over MCP
