API
Every public name in viewportai.evals and @viewportai/evals, side by side, with the modules and subpaths they live in.
Python is viewportai.evals (PyPI viewport-evals); TypeScript is @viewportai/evals (npm). Concepts and names
match; each language keeps its own idiom (snake_case and keyword arguments in Python, camelCase and option objects
in TypeScript). Wire data, such as expect: blocks, verdicts and reports, uses the same snake_case keys in both.
Parity table
| Concept | Python | TypeScript |
|---|---|---|
| Capture a run | with trace() as t: / async with trace() as t: | const t = await trace(fn, options?) |
| Trace options | sink, fixture, mode, instrument, pricing, judge, assertions, replay, allow_empty, input, clock, patch, ids, store | sink, fixture, mode, instrument, pricing, judge, assertions, replay, allowEmpty, clock, patch, ids, store |
| The result | Trace | Trace |
| Tool called? | t.called("x", a=1) returns a truthy Check | t.called("x", { a: 1 }) returns a boolean |
| Full expectations | t.meets({...}), await t.ameets({...}) return a Check | await t.meets({...}) returns a Check |
| Invariants | t.upholds(invs) (a truthy Check), t.violations(invs), violations(invs, trajectory), load_invariants(path), parse_invariants_file, Invariant, Violation, InvariantLoadError, InvariantWarning | t.upholds(invs), t.violations(invs), violations(invs, trajectory), loadInvariants(path), loadInvariantsSync, parseInvariantsFile, InvariantLoadError |
| Worlds | world(name, state=) with @w.tool, w.create(seed), w.extend(...), World, WorldInstance, WorldError, WorldChange, WorldFault | defineWorld({ name, state }).tool(name, spec, fn), w.create(seed), w.extend({ name }), World, WorldInstance, WorldError |
| World packs | viewportai.evals.worlds: crm, calendar, payments, inbox | @viewportai/evals/worlds: crm, calendar, payments, inbox, packs |
| Simulated clock | simulated_clock(start), SimulatedClock, current_simulated_clock(), trace(clock=, patch=) | simulatedClock(start), SimulatedClock, currentSimulatedClock(), trace(fn, { clock, patch }) |
| Production replay | import_traces, parse_traces, sample_traces, redact_trajectory, ImportedTrace, RecordedTools (serve with core's tool_server) | importTraces, parseTraces, sampleTraces, redactTrajectory, langfuseTraces, langsmithTraces, braintrustTraces, RecordedTools (serve with core's withToolServer) |
| Behavior diff | t.diff(baseline), trajectory_diff(a, b), format_diff, TrajectoryDiff | t.diff(baseline), trajectoryDiff(a, b), formatDiff |
| Simulated users | converse(agent, user), run_cases(..., user=), viewportai.evals.simulate: Conversation, UserTurn, openevals_user | converse(agent, user, options), runCases(cases, { user, maxTurns }), Conversation, UserTurn, openevalsUser |
| Model matrix and flakes | run_cases(..., models=, repeat=), CaseInput.model | runCases(cases, { models, repeat }), CaseInput.model |
| Test fixture | trajectory and clock (pytest fixtures) | none; call trace() in the test |
| Assertion matchers | plain assert on the Trace | toHaveCalledTool, toHaveModelCalls, toBeWithinBudget, toHaveRequestedApproval, toHaveLoadedSkill, toUphold, toMeet from @viewportai/evals/vitest |
| Repeated runs | @pytest.mark.viewport(runs=, pass_threshold=, min_passes=) | repeat({ runs, passThreshold, minPasses }, fn), throws RepeatError |
| YAML cases as tests | collected automatically by the pytest plugin | describeCases(globs, options?) from @viewportai/evals/vitest/cases |
| Load cases | load_cases(globs, cwd=), parse_case_file(text, file), find_case_files, is_case_document, CaseFileWarning | loadCases(globs, { cwd, onWarning }), loadCasesSync, parseCaseFile(text, file), isCaseDocument |
| Run cases | run_cases(cases, config=, mode=, ci=, concurrency=, store=, reporters=, results=), run_case, arun_cases, arun_case, RunOptions (every field optional) | runCases(cases, { config, mode, ci, concurrency, store, clock, ids, signal, onCaseStart, onCaseDone, reporters, results }), runCase |
| Evaluate a trajectory | evaluate(expect, trajectory, ctx), aevaluate | evaluate(expect, trajectory, ctx) (async) |
| Config file | [tool.viewport.evals] in pyproject.toml | viewport.config.ts, key evals |
| Build config in code | resolve_config(agent=, agents=, cases=, ...), load_config() | defineConfig({ evals }), resolveConfig(config), loadConfig(), validateConfig, configFromEnv |
| Register an agent | agent = "module:attr" in config, or @agent / @agent("name") | agent / agents in config |
| Agent input | CaseInput (prompt, history, context, session, case_id, turn, worlds, event, episode, model) | CaseInput (prompt, history, context, session, caseId, turn, worlds, event, episode, model, signal) |
| Assertion plugin | @assertion("name"), returning bool or Outcome | defineAssertion({ options, check }), registered under assertions |
| Judges | llm_judge(complete=), judge(rubric, threshold=) | llmJudge({ complete, prompt? }), judgePrompt, judge(rubric, { threshold }) |
| Matcher helpers | equals lt lte gt gte contains not_contains icontains starts_with ends_with regex len_ is_ exists jsonpath json_schema any_of all_of not_ fields judge | same in camelCase, len, is, not, plus the m namespace |
| Fixture stores | FileFixtureStore(root=None), MemoryFixtureStore, FixtureStore protocol | fileFixtureStore, fileFixtureStoreAt(root), memoryFixtureStore, FixtureStore, fixturePathFor, parseFixture, formatFixture |
| Prices | DEFAULT_PRICES, ModelPrice | DEFAULT_PRICES, ModelPrice, mergePrices, trajectoryCost |
| Adapters | instrument(option) | instrument(option), AUTO_INSTRUMENT |
| Errors | ViewportEvalsError, FixtureError, ConfigError, CaseLoadError | same, plus ReplayMissError |
| Version | __version__ | version in package.json |
Loading by glob keeps only case files: a $schema naming the case schema, or a top-level input or cases.
Other YAML under evals/ is skipped by the pytest plugin, load_cases / loadCases and both CLIs; one that looks
like a mistyped case (inputs:, or expect without input) warns not a case file?. A file given by path always
loads, so its errors show.
The pytest plugin collects every case file the cases globs match. When your cases need setup pytest does not do
(a database, a launched worker), turn collection off with collect = false under [tool.viewport.evals] and run
them with viewport-evals run or run_cases, or narrow it with collect = ["evals/golden/**/*.yaml"]. collect
only affects the pytest plugin; the CLI and run_cases still use cases. In TypeScript, YAML cases become tests only
where you call describeCases, so there is nothing to turn off.
config is optional everywhere: without it, run_cases reads the nearest pyproject.toml and runCases loads
viewport.config.* from the working directory, as the CLI does. reporters get every hook in order (on_run_start,
on_case_done, on_run_end, plus the live hooks of results_reporter), and results=True / results: true writes
the results directory to the config's results_dir (or pass a directory). Both
are off by default in code; the CLI and the pytest plugin turn results on outside CI.
Both re-export Viewport Core's emit and its tool helpers (tool in Python, defineTool and Tool in TypeScript).
TypeScript also exports the replay internals (ReplaySession, withReplay), the dedupe helpers
(dedupeEvents, dedupeModelCalls, dedupeToolCalls), setTraceFixtureResolver for other test runners, the run
helpers defaultMode, isCi, MODES and requiredPasses, and every reporter. Python exposes
trace_fixture(path, id) to point trace() scopes at a fixture file outside pytest.
Modules and subpaths
| Purpose | Python | TypeScript |
|---|---|---|
| Main API | viewportai.evals | @viewportai/evals |
| Test helpers | viewportai.evals.testing | @viewportai/evals/testing |
| Test runner | pytest_plugin (loaded by pytest's entry point, never imported by the main module) | @viewportai/evals/vitest (setup file), @viewportai/evals/vitest/cases |
| Reporters | viewportai.evals.reporters | @viewportai/evals |
| Results directory | viewportai.evals.results | @viewportai/evals/results |
| World packs | viewportai.evals.worlds | @viewportai/evals/worlds |
| Simulated users | viewportai.evals.simulate (also converse from the main module) | @viewportai/evals |
| Anthropic SDK | viewportai.evals.anthropic: wrap(client) | @viewportai/evals/anthropic: wrap(client) |
| OpenAI SDK | viewportai.evals.openai: wrap(client) | @viewportai/evals/openai: wrap(client) |
| LangGraph | viewportai.evals.langgraph: ViewportCallbackHandler, auto_instrument | @viewportai/evals/langgraph: viewportCallbacks, ViewportCallbackHandler, autoInstrument |
| OpenAI Agents SDK | viewportai.evals.openai_agents: ViewportProcessor, auto_instrument | @viewportai/evals/openai-agents: viewportProcessor, autoInstrument |
| Claude Agent SDK | viewportai.evals.claude_agent_sdk: query, capture | @viewportai/evals/claude-agent-sdk: query, capture |
| Vercel AI SDK | none | @viewportai/evals/ai-sdk: viewportTelemetry, captureMiddleware, autoInstrument |
| OpenTelemetry | viewportai.evals.otel: span_processor, import_otlp, otlp_spans | @viewportai/evals/otel: spanProcessor, importOtlp, otlpSpans |
| JSON Schemas | viewport-evals schema | @viewportai/evals/schemas/*, viewport-evals schema |
Testing helpers
| Python | TypeScript | What it is |
|---|---|---|
script(*steps, model=) | script(...steps, { model }) | a scripted model; targets below |
tool_call(name, **args) | toolCall(name, args) | a turn that calls one tool |
tool_error(name, raw) | toolError(name, raw) | a turn whose arguments are not valid JSON (invalid_tool_call) |
reply(text) | reply(text) | a turn that answers and stops |
turn(*steps) | turn(...steps) | several calls in one turn (parallel tool calls) |
when(test, step) | when(test, step) | a turn served only when test(request) holds |
.anthropic(), .async_anthropic(), .openai(), .async_openai() | .anthropic(), .openai(), .fetch() | real SDK clients served by the script |
.langgraph(), .openai_agents() | .langgraph(), .openaiAgents(), .aiSdk() | framework models |
.serve(), .claude_agent_sdk() | serveScript(script), .claudeAgentSdk() | the script over HTTP on 127.0.0.1 |
.assert_consumed(), .requests, .served | .assertConsumed(), .requests, .served | checks and inspection |
fake_tool(name, returns=, raises=, handler=) | fakeTool(name, { returns, raises, handler }) | a recorded tool with scripted behavior and a calls log |
fake_judge([...]) | fakeJudge([...]) | a judge with scripted verdicts and a requests log |
MemoryFixtureStore | memoryFixtureStore() | an in-memory fixture store |
FakeClock, SequentialIds, trajectory(), collect(), normalize | same | deterministic building blocks from Viewport Core |
Scripted usage is computed when you omit it (a deterministic estimate, the same in both languages) and can be set
per turn with usage=. Running past the end of a script raises evals.script_exhausted with the unexpected
request. Fakes emit their own model_call events, so a test with an unwrapped fake client is still captured.