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:
# 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")// 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:
# 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// 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:
# 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// 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 3Operators and helpers
| Operator | Passes when | Python helper | TypeScript helper |
|---|---|---|---|
equals | deep equal (exact, not partial) | equals(v) | equals(v) |
gt gte lt lte | the number comparison holds | gt(n) ... lte(n) | gt(n) ... lte(n) |
contains | substring of a string, or some array element matches | contains(m) | contains(m) |
not_contains | the negation of contains | not_contains(m) | notContains(m) |
icontains | case-insensitive substring | icontains(s) | icontains(s) |
starts_with, ends_with | prefix or suffix | starts_with(s), ends_with(s) | startsWith(s), endsWith(s) |
regex | RE2 search, unanchored; flags i, m, s | regex(p, flags) | regex(p, flags) |
glob | anchored glob: *, ?, [a-z] | none: write {"glob": "..."} | none: write { glob: "..." } |
len | length of a string, array or object is in a Range | len_(r) | len(r) |
is | the JSON type: string, number, integer, boolean, object, array, null | is_(t) | is(t) |
exists | present (true) or missing (false) | exists(b) | exists(b) |
jsonpath | every node the path selects matches | jsonpath(path, m) | jsonpath(path, m) |
json_schema | the value validates against a JSON Schema | json_schema(s) | jsonSchema(s) |
any_of, all_of | some or every matcher passes | any_of(*ms), all_of(*ms) | anyOf(...ms), allOf(...ms) |
not | the matcher fails | not_(m) | not(m) |
fields | partial match on field names that collide with operators | fields(**f) | fields(f) |
judge | a judge passes the value | judge(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_schemaandjsonpathparse a string that holds JSON, and anoutputcheck unwraps a fenced json block first, sooutput: { jsonpath: { $.status: issued } }works on a model's JSON answer.- String operators never stringify: the number
42does 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.