Skip to Content
Judgment Labs
Tests

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.

  1. Call get_skill with build-test-suite and follow it.
  2. Call list_projects and pick the project the agent sends traces to. Call list_test_suites. If a suite for this purpose exists, add to it instead of creating another.
  3. Call list_judges with version: "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.
  4. 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.
  5. Call create_test_suite, then add_test_cases. Give each case a name that states what should happen, the input in the shape the agent's entry point reads, and its checks in expected, each with a rationale.
  6. Call publish_test_suite. Only a published version runs.
  7. 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 what judgeval test run runs by default. If the repo has no .judgment/ folder, follow Set up tests in your repo.
  8. 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 runnable

Each entry in expected is a check. It passes when the judge's output, compared with expected using op, is true:

opPasses when
eq, neThe output equals (or does not equal) expected.
lt, lte, gt, gteThe output compares to expected as a number.
in, not_inThe 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 metadata are 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 input is the trace's root span input and whose metadata.trace_id points 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.2 is major version 1, minor version 2.
  • With MCP: the list_judges and get_judge tools 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 2

client.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):

SDKRoute
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

On this page