Skip to main content

Stochast

A testing tool for LLM agents that reports pass rates instead of pass/fail verdicts. Agents are non-deterministic: the same prompt can take a different tool-call path on every run, so a single pass or fail tells you almost nothing. Stochast runs a scenario N times and reports how often it passed.

# scenarios.py
from stochast import scenario, expect
from stochast.adapters.openai import OpenAIAdapter, ToolSpec


def lookup_order(order_id: int) -> dict:
    return {"order_id": order_id, "status": "shipped"}


def build_adapter():
    return OpenAIAdapter(
        model="gpt-4o-mini",
        api_key="sk-...",
        tools=[
            ToolSpec(
                name="lookup_order",
                description="Look up an order by id",
                parameters={
                    "type": "object",
                    "properties": {"order_id": {"type": "integer"}},
                    "required": ["order_id"],
                },
                handler=lookup_order,
            )
        ],
    )


@scenario(runs=20)
def refund_status_lookup(agent):
    result = agent.run("What's the status of order 4471?")
    expect.tool_called(result, "lookup_order")
    expect.output_contains(result, "4471")
stochast run scenarios.py --adapter scenarios:build_adapter
refund_status_lookup (20 runs)
  pass rate: 18/20 (90%)

Every run is persisted as JSON under stochast-results/ for later inspection.

Retry policy

Stochast retries transport errors (timeouts, connection failures, 429s, 5xxs) with backoff, because those are infrastructure problems. It never retries anything else: a model calling the wrong tool or giving a bad answer is data, and retrying it would silently destroy the measurement you're trying to take.

Status

Early and incomplete. Currently implemented: the @scenario decorator, an OpenAI-compatible tool-calling adapter, a concurrent runner with the retry policy above and Ctrl-C-safe partial results, and two assertions (tool_called, output_contains). Confidence intervals, the full assertion vocabulary, tool-path frequency tables, cost/latency percentiles, and A/B comparison are planned but not yet built.

Install

pip install stochast

Requires Python 3.11+.

Release files for stochast 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stochast 0.1.0
File Size Uploaded
stochast-0.1.0.tar.gz 53.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stochast 0.1.0
File Interpreter ABI Platform
stochast-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 65.6 kB

Release files / stochast-0.1.0.tar.gz

Download URL stochast-0.1.0.tar.gz
Size 53.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f05e8a07b3544349b4d2ae70bbbefc698a7e5e784cebf67f29ffdfe87e162f0d
BLAKE2b-256 checksum
How to use checksums
c05318484720947485722baeb7e5c58f5acd069bfe22a3e9c00ee7a017a4a22c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / stochast-0.1.0-py3-none-any.whl

Download URL stochast-0.1.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
adec213d2da6a6a9f7e4049d576b348ff5166b4b4c4bcdc25dbab90e56c646b3
BLAKE2b-256 checksum
How to use checksums
864d6f092e25e51e21d13b040f9798f0bae63d2a028236e24632e1fc67e6cb60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page