Evals

Matchers

One plain-data language for tool arguments, results and output, in YAML and in code, with helpers in both languages.

A matcher is plain data, so a YAML case, an inline t.meets({...}) and a helper call such as lte(100) are the same document. The engine is Viewport Core's, shared with HITL policies, and both languages give the same answer and the same failure message.

  • A literal (string, number, boolean, null) matches by deep equality.
  • An object whose keys are all operators applies every operator: { gt: 0, lte: 100 }.
  • Any other object is a partial pattern: listed keys must match, extra keys are allowed, a missing key fails.
  • An object that mixes operators and field names is a load error. To match a field whose name is an operator, use fields: { fields: { is: "refund" } }.

In code

t.called(tool, args) checks that some call to tool has matching arguments. Helpers build operator objects:

main.py
# Plain values match by equality, dicts match partially, helpers build operator objects.
assert t.called("issue_refund", order_id="A-1001")
assert t.called("issue_refund", order_id=regex(r"^A-\d+$"), amount=lte(100))
assert t.called("lookup_order", order_id=any_of("A-1001", "A-2002"))
assert not t.called("issue_refund", amount=lte(10))
assert not t.called("delete_account")
main.ts
// Plain values match by equality, objects match partially, helpers build operator objects.
assert.ok(t.called("issue_refund", { order_id: "A-1001" }));
assert.ok(t.called("issue_refund", { order_id: regex("^A-\\d+$"), amount: lte(100) }));
assert.ok(t.called("lookup_order", { order_id: anyOf("A-1001", "A-2002") }));
assert.equal(t.called("issue_refund", { amount: lte(10) }), false);
assert.equal(t.called("delete_account"), false);

t.meets(...) takes a whole expect: block, and literal operator objects work as well as helpers:

main.py
# The full ``expect:`` shape, inline. Helpers and literal operator dicts are the same document.
check = t.meets(
    {
        "tools": {
            "exactly": ["lookup_order", "issue_refund"],
            "no_errors": True,
            "calls": [
                {
                    "tool_name": "issue_refund",
                    "args": {"amount": {"gt": 0, "lte": 100}, "reason": {"icontains": "damaged"}},
                    "which": "all",
                }
            ],
        },
        "model_calls": {"max": 3},
        "budget": {"tokens": 2000, "cost_usd": 0.01},
        "output": [{"contains": "R-1001"}, {"not": {"icontains": "sorry"}}],
    }
)
assert check, check
main.ts
// The full `expect:` shape, inline. Helpers and literal operator objects are the same document.
const check = await t.meets({
  tools: {
    exactly: ["lookup_order", "issue_refund"],
    no_errors: true,
    calls: [
      {
        tool_name: "issue_refund",
        args: { amount: { gt: 0, lte: 100 }, reason: { icontains: "damaged" } },
        which: "all",
      },
    ],
  },
  model_calls: { max: 3 },
  budget: { tokens: 2000, cost_usd: 0.01 },
  output: [{ contains: "R-1001" }, { not: { icontains: "sorry" } }],
});
assert.ok(check.passed, check.message);

A failed check explains itself, one line per failed assertion, with the path, the expectation and the actual value:

main.py
# A failed check is falsy and its repr explains it, so a bare ``assert`` prints why.
miss = t.meets({"tools": {"exactly": ["lookup_order"]}, "model_calls": 2})
assert not miss
print(miss)
# tools.exactly: expected exactly lookup_order; got lookup_order > issue_refund
# model_calls: expected exactly 2 model calls; got 3
main.ts
// A failed check explains itself: one line per failed assertion.
const miss = await t.meets({ tools: { exactly: ["lookup_order"] }, model_calls: 2 });
assert.equal(miss.passed, false);
console.log(miss.message);
// tools.exactly: expected exactly lookup_order; got lookup_order > issue_refund
// model_calls: expected exactly 2 model calls; got 3

Operators and helpers

OperatorPasses whenPython helperTypeScript helper
equalsdeep equal (exact, not partial)equals(v)equals(v)
gt gte lt ltethe number comparison holdsgt(n) ... lte(n)gt(n) ... lte(n)
containssubstring of a string, or some array element matchescontains(m)contains(m)
not_containsthe negation of containsnot_contains(m)notContains(m)
icontainscase-insensitive substringicontains(s)icontains(s)
starts_with, ends_withprefix or suffixstarts_with(s), ends_with(s)startsWith(s), endsWith(s)
regexRE2 search, unanchored; flags i, m, sregex(p, flags)regex(p, flags)
globanchored glob: *, ?, [a-z]none: write {"glob": "..."}none: write { glob: "..." }
lenlength of a string, array or object is in a Rangelen_(r)len(r)
isthe JSON type: string, number, integer, boolean, object, array, nullis_(t)is(t)
existspresent (true) or missing (false)exists(b)exists(b)
jsonpathevery node the path selects matchesjsonpath(path, m)jsonpath(path, m)
json_schemathe value validates against a JSON Schemajson_schema(s)jsonSchema(s)
any_of, all_ofsome or every matcher passesany_of(*ms), all_of(*ms)anyOf(...ms), allOf(...ms)
notthe matcher failsnot_(m)not(m)
fieldspartial match on field names that collide with operatorsfields(**f)fields(f)
judgea judge passes the valuejudge(rubric, threshold=...)judge(rubric, { threshold })

TypeScript also exports every helper on the m namespace (m.lte(100)). Python appends an underscore where the name is a keyword or builtin (is_, not_, len_). Vitest's asymmetric matchers (expect.any(...)) are not accepted inside Viewport matchers: one language, so YAML and code agree.

Details that keep both languages identical:

  • Regex is RE2 everywhere: linear time, no lookaround, no backreferences.
  • JSONPath is a subset of RFC 9535 ($, .name, ['name'], [n], [-n], [*], .*); filters and .. are load errors.
  • json_schema and jsonpath parse a string that holds JSON, and an output check unwraps a fenced json block first, so output: { jsonpath: { $.status: issued } } works on a model's JSON answer.
  • String operators never stringify: the number 42 does not contain "4". A matcher applied to the wrong type is "unknown", which fails an expectation and says why.

Mistakes are caught when the case loads, with file, line and column: unknown operators with a did-you-mean, an invalid regex or JSONPath, min greater than max, and the pre-1.0 operator names type, path, length and schema (now is, jsonpath, len and json_schema).

Tool name globs

Names in every sequence key, in tools.calls[].tool_name, in approvals and gated, in invariant selectors, and in t.calls and t.called may be globs: mcp__crm__* matches every tool of an MCP server, *_refund every refund tool. * matches any run of characters, ? one, [a-z] a class.

Secret arguments

A tool argument whose schema marks it writeOnly: true (pydantic SecretStr, SecretBytes) is recorded as [redacted hmac:<12 hex>], never as the real value; the tool itself still receives the real value. A matcher over that field, in tools.calls[].args, an invariant or use:, sees the marker string. { exists: true } passes, { regex: "^\\[redacted hmac:" } checks that it was masked, and a match on the real value fails. Assert on the non-secret arguments, or on the tool's result.

This masking covers the trajectory: the tool_call events matchers read, and everything built from them (fixture trajectories, the results directory, reporters, exporters). It does not reach the model traffic in a fixture's exchanges: if the model writes the secret into a tool call, or a later request carries it back in its messages, the stored exchange holds it as sent unless it has a credential shape the redaction list masks or replay.redact removes it. See redaction.

Next: judges and plugins.

On this page