Run your first test suite
Create a test suite with one case, run a sample agent against it, and read the result.
In this tutorial, you create a judge and a test suite with one case, run a
sample agent against it with judgeval test run, and read the result. The
tutorial takes a few minutes and uses one judge evaluation.
Run your first test suite with your coding agent
Paste it into your agent from your repo's root.
A coding agent can do every step below except creating the judge in the app.
With the Judgment MCP server connected, it can create the judge with
create_judge instead, after loading the configure-judge skill with
get_skill. To set tests up for your real agent, use
Set up tests in your repo.
Prerequisites
- Python and judgeval 1.11.0 or later, with the
JUDGMENT_API_KEYandJUDGMENT_ORG_IDenvironment variables set. Use a personal API key: an ingest API key can't start a test run. - A project in Judgment. The steps use one named
support-agent. - The Developer role or higher in the organization that owns the project. This role applies to every project in that organization. Ask an Admin or Owner for a role change if needed, and replace
support-agentwith the exact project name. - Check your evaluation allowance. The fixed-text sample needs no provider key; your own agent also needs its runtime, provider credentials and tools.
Create the judge
In the support-agent project, open Judges and create a judge that asks
whether the final answer tells the customer they were refunded, with two
labels: Yes and No. See Create a judge.
Open the judge and note two things for the next step:
- Its ID, the last part of the page URL (
…/judges/<judge_id>). - Its version from the version menu. For
v1.0, the major version is1and the minor version is0.
Create the test suite
Work in an empty folder. Save this as create_suite.py and run it once with
python create_suite.py:
from judgeval import Judgeval
JUDGE_ID = "<judge_id>" # from the judge's page URL
JUDGE_MAJOR, JUDGE_MINOR = 1, 0 # from the judge's version menu
client = Judgeval(project_name="support-agent")
# A test suite with one case that expects the judge to return Yes.
suite = client.test_suites.create(name="my-first-test-suite")
client.test_suites.add_cases(suite["test_suite_id"], [{
"name": "Double charge is refunded",
"input": {"question": "I was charged twice"},
"expected": {
JUDGE_ID: {
"judge_major_version": JUDGE_MAJOR,
"judge_minor_version": JUDGE_MINOR,
"op": "eq",
"expected": "Yes",
},
},
}])
client.test_suites.publish(suite["test_suite_id"]) # version 1 is now runnableTest suite names must be unique in the project. To run the script again,
change the name or delete the earlier test suite with
client.test_suites.delete(test_suite_id).
Add a sample agent
Save this as my_agent.py in the same folder. It stands in for your agent:
one traced function that returns a fixed answer.
from judgeval import Tracer
@Tracer.observe(span_type="agent")
def support_agent(question):
return "Sorry about that! I've refunded the duplicate charge."Tell Judgment how to run the agent
In the same folder, run:
judgeval test init --project support-agent --suite my-first-test-suiteThis writes .judgment/judgment.json, which names the project and the suite
to run, and .judgment/run.py. Replace the contents of .judgment/run.py
with:
from my_agent import support_agent
def run(case, environment):
return support_agent(case["input"]["question"])judgeval test run calls run once per case. case["input"] is the input
you stored on the case. environment is None here, because the case names
no test environment.
Run the suite
judgeval test runThe command starts a run, calls run for the case, and waits until Judgment
has scored the trace. Test traces are stored under the Test Runs
environment, apart from production traces (see
Keep test traces separate).
Expected result
Within about a minute, the command prints a single passing case and exits with
code 0:
my-first-test-suite: 1 passed, 0 failed, 1 total
Run: https://app.judgmentlabs.ai/org/…/offline-tests/…/runs/…Open the link to read the judge's reason for its answer. The reason cites the trace spans the judge relied on.
To see a failing case, change the sample agent's answer so that it no longer
mentions a refund, and run judgeval test run again. The same case then
fails, and the command exits with code 1:
my-first-test-suite: 0 passed, 1 failed, 1 total
FAILED Double charge is refunded
<judge name>: expected eq Yes, got No
<the judge's reason>
Run: https://app.judgmentlabs.ai/org/…/offline-tests/…/runs/…
1 test case(s) failedNext steps
- Set up tests in your repo for your real agent, and run them in CI.
- Create and edit a test suite with your own cases.