Create and edit a test suite
Write test cases with the judges to run and the answers you expect, then publish them as a version.
A test suite is a set of cases. Each case has an input for your agent and an
expected object that names the judges to run on the case's trace and the
result each judge should return. At the end of this guide, the test suite has a
published version that you can run.
Build a test suite with your coding agent
Paste it into your agent from your repo's root.
Prerequisites: judgeval 1.4.0 or later (Python or TypeScript), and at least one judge in the project, with its ID and version (see Find a judge's ID).
Instructions for the coding agent
These steps need the Judgment MCP server. If you don't have its tools, follow Connect your coding agent, or use the SDK calls in the rest of this page.
- Call
get_skillwithbuild-test-suiteand follow it. - Call
list_projectsand pick the project the agent sends traces to. Calllist_test_suites. If a suite for this purpose exists, add to it instead of creating another. - Call
list_judgeswithversion: "production". Each check names a judge by its ID and version, and expects one of that judge's labels. If no judge answers what a case needs to check, ask the user before you create one. - Choose 5 to 10 inputs. Take them from real traces of behavior that works today, or from the user. Don't invent scenarios the agent never sees.
- Call
create_test_suite, thenadd_test_cases. Give each case anamethat states what should happen, theinputin the shape the agent's entry point reads, and its checks inexpected, each with arationale. - Call
publish_test_suite. Only a published version runs. - If the repo has a
.judgment/judgment.json, put the suite's name under"suites"when every change should run it. That makes it part of whatjudgeval test runruns by default. If the repo has no.judgment/folder, follow Set up tests in your repo. - Tell the user the suite's name, its cases, and the judge each case checks with.
The suite that every change must keep passing is your baseline suite. Name
it for that, such as Baseline, and list it under "suites" in
judgment.json.
Create a test suite and add cases
from judgeval import Judgeval
client = Judgeval(project_name="support-agent")
suite = client.test_suites.create(name="support-agent-regressions")
client.test_suites.add_cases(suite["test_suite_id"], [
{
"input": {"question": "I was charged twice"},
"tags": ["billing"],
"expected": {
REQUEST_TYPE_JUDGE_ID: { # a judge with the labels refund, billing, other
"judge_major_version": 1, "judge_minor_version": 0,
"op": "eq", "expected": "refund",
"rationale": "A double charge is resolved with a refund",
},
TOOL_CALLS_JUDGE_ID: { # a judge that returns a number
"judge_major_version": 1, "judge_minor_version": 0,
"op": "lt", "expected": 3,
},
},
},
])
client.test_suites.publish(suite["test_suite_id"]) # version 1 is now runnableEach entry in expected is a check. It passes when the judge's output,
compared with expected using op, is true:
op | Passes when |
|---|---|
eq, ne | The output equals (or does not equal) expected. |
lt, lte, gt, gte | The output compares to expected as a number. |
in, not_in | The output is (or is not) in expected, a list. |
A judge's output is the label it chose, such as "Yes" or "refund". Older
judges that return a score or true/false output that value instead.
ne and not_in pass on every other label, including a catch-all such as
other. To fail on those, use eq or in with the labels that count as a
pass.
Which op you can use depends on the judge. Judges that return a score work
with every op. Judges that choose a label work with eq, ne, in, and
not_in. Judges that return true/false work with eq and ne.
A check grades the trace whose root span carries the case's attributes.
A check can also have a rationale: why it expects that value. Run results
show it next to the judge's verdict, so anyone reviewing a disagreement can see
why the case expects what it does.
Judges never receive the expected value or the rationale, so the same judge can be used in
online monitoring and in test suites. A case runs only the judges listed in its
expected. If a judge ID or version doesn't exist in the project, or a check
uses an op the judge doesn't support, the case isn't added. If a judge is
deleted after that, its check fails with Judge not found when the
case is scored.
Besides input, expected and tags, a case can have a name and a
metadata object. Only input is required. One call adds up to 1,000 cases.
Code judges read the case's metadata keys as fields of the example they
score, the same way they read dataset columns in a test config, so a code
judge can compare the trace against a reference value stored there. Agent
judges don't see metadata.
Keys that identify a trace, span, session or conversation are reserved: code judges don't receive them as fields. Which trace a case's checks grade depends on the run:
- A normal run grades the trace your agent produces for the case. Trace
IDs in
metadataare ignored. - A stored-trace run
grades the trace the case names in
metadata.trace_id, without running your agent.
example_id and created_at are also replaced, by the case's ID and the time
of scoring, and name is ignored.
To run a case with canned tool results and starting data, name a test
environment in metadata.environment. Test environments are in early access;
see
Run cases in a test environment.
Add cases from traces
To test against traces you already have, such as the traces in a dataset, a judge's labels, or an Issue's evidence, make each one a case:
- In the app: select traces in the traces table, a session's trace list,
or a judge's Labels table, or open a single trace, and choose Add to
test case. Pick a test suite or create one. Each trace becomes a draft case
whose
inputis the trace's root span input and whosemetadata.trace_idpoints at the trace. Up to 1,000 traces at a time. - From code: put the trace's ID in the case's
metadata:
client.test_suites.add_cases(suite["test_suite_id"], [
{
"input": {"question": "I was charged twice"},
"metadata": {"trace_id": TRACE_ID},
"expected": {
REQUEST_TYPE_JUDGE_ID: {
"judge_major_version": 1, "judge_minor_version": 0,
"op": "eq", "expected": "refund",
},
},
},
])Add the checks each case needs, then publish. A stored-trace run needs a
trace on every case in the published version, so keep trace-backed cases in
their own test suite. To grade those traces without running your agent, start the run with stored traces; see
Score stored traces.
To run your agent on each case instead, start a normal run: the case's input
is replayed and metadata.trace_id is ignored.
From a dataset
A dataset's page has no Add to test case action, so copy its rows in from
code. Each row's trace field becomes metadata.trace_id. A
golden dataset
also has an expected_<judge name> field holding your label, which becomes
that judge's check:
dataset = client.datasets.get(name="request-completed-golden")
client.test_suites.add_cases(suite["test_suite_id"], [
{
# A stored-trace run doesn't replay the input, but every case needs one.
"input": example["input"] if "input" in example else {},
"metadata": {"trace_id": example["trace"]},
"expected": {
REQUEST_COMPLETED_JUDGE_ID: {
"judge_major_version": 1, "judge_minor_version": 0,
"op": "eq", "expected": example["expected_request_completed"],
},
},
}
for example in dataset.examples
])
client.test_suites.publish(suite["test_suite_id"])For a dataset of agent inputs, use each row's input as the case input, leave
out metadata.trace_id, and start a normal run. A dataset with a session field
instead of a trace field can't be graded as stored traces: a stored-trace run
grades one trace per case.
Find a judge's ID and version
- In the app: open the judge. Its ID is the last part of the page URL
(
…/judges/<judge_id>), and its versions are in the version menu on the judge page.v1.2is major version1, minor version2. - With MCP: the
list_judgesandget_judgetools return a judge's ID and version. See MCP tools.
Use lowercase judge IDs as the keys of expected.
Edit published cases
Published versions are immutable. Changes are made in the test suite's draft, which becomes the next version when you publish it. New cases are added directly to the draft. To edit or remove a published case, create the draft first.
client.test_suites.create_draft(test_suite_id) # copy the published cases into the draft
client.test_suites.update_case(test_suite_id, case_id, {...})
client.test_suites.remove_case(test_suite_id, other_case_id)
client.test_suites.publish(test_suite_id) # version 2client.test_suites.discard(test_suite_id) discards the draft's changes. Earlier
versions, and the runs that used them, are unaffected.
client.test_suites.delete(test_suite_id) deletes the test suite with all its
versions, runs and results.
Verify
client.test_suites.list_cases(test_suite_id) returns the latest published version's
cases. Pass version="draft" to see the draft, or a version number for an
older version.
In TypeScript, the same methods are on judgeval.testSuites in camelCase, such
as addCases, createDraft and listCases. See the
Python and
TypeScript SDK reference.
Use the HTTP API
Every SDK call maps to a route under
https://api.judgmentlabs.ai/v1/projects/$JUDGMENT_PROJECT_ID/test-suites,
called with your API key and organization ID (see
Authentication):
| SDK | Route |
|---|---|
test_suites.create(name) | POST /test-suites |
test_suites.list() | GET /test-suites |
test_suites.delete(test_suite_id) | DELETE /test-suites/{test_suite_id} |
test_suites.list_cases(test_suite_id) | GET /test-suites/{test_suite_id}/cases |
test_suites.add_cases(test_suite_id, cases) | POST /test-suites/{test_suite_id}/cases |
test_suites.create_draft(test_suite_id) | POST /test-suites/{test_suite_id}/draft |
test_suites.update_case(test_suite_id, case_id, case) | PUT /test-suites/{test_suite_id}/cases/{case_id} |
test_suites.remove_case(test_suite_id, case_id) | DELETE /test-suites/{test_suite_id}/cases/{case_id} |
test_suites.publish(test_suite_id) | POST /test-suites/{test_suite_id}/publish |
test_suites.discard(test_suite_id) | POST /test-suites/{test_suite_id}/discard |
Creating, editing, publishing and deleting need the Developer role or higher.
Next steps
- Set up tests in your repo to run the suite with
judgeval test run. - Run your agent on the test suite and read each case's result.