Skip to main content

assertllm

assertllm

The pytest for LLMs. Test your AI outputs like you test your code.

PyPI version Python 3.10+ License: MIT

Quick Start

pip install assertllm[anthropic]
from assertllm import expect, llm_test

@llm_test(
    expect.contains("Paris"),
    expect.latency_under(2000),
    expect.cost_under(0.001),
    model="claude-sonnet-4-6",
)
def test_capital(llm):
    llm("What is the capital of France?")
pytest test_capitals.py -v
test_capitals.py::test_capital
  AI response: "The capital of France is Paris."
  ✓ contains("Paris")
  ✓ latency_under(2000) — 823ms
  ✓ cost_under(0.001) — $0.000023
  PASSED

────────── assertllm summary ──────────
  LLM tests: 1 passed
  Assertions: 3/3 passed
  Total cost: $0.000023
  Avg latency: 823ms

Features

  • 22+ assertions — text, performance, agent, composable
  • Zero LLM calls for most checks — deterministic and instant
  • Built on Pydantic — auto-validation, JSON serialization, schema generation
  • Multi-provider — OpenAI, Anthropic, Ollama out of the box
  • Agent testing — tool calls, loop detection, call ordering
  • Retry support — handle non-deterministic outputs
  • CI/CD native — pytest markers, JUnit XML, JSON reporters
  • Pydantic AI integration — test your existing agents

Installation

pip install assertllm[anthropic]    # Anthropic
pip install assertllm[openai]       # OpenAI
pip install assertllm[ollama]       # Ollama (local)
pip install assertllm[all]          # Everything

Documentation

Full docs at docs.assertllm.dev

Contributing

git clone https://github.com/bahadiraraz/llmtest
cd llmtest
uv sync --all-extras
uv run pytest tests/ -v

Roadmap

This library is under active development. More providers (Gemini, DeepSeek, Mistral, etc.) and additional assertion types are coming soon.

License

MIT

Metadata

Release files for assertllm 0.3.1

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

Source distribution (sdist)

Source distribution for assertllm 0.3.1
File Size Uploaded
assertllm-0.3.1.tar.gz 34.1 kB Details

Built distribution (wheel)

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

Total release size: 77.6 kB

Release files / assertllm-0.3.1.tar.gz

Download URL assertllm-0.3.1.tar.gz
Size 34.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a0d4e5053a74676050240ddd0580b187892c00095b26f36b56253ff8cdd3f50c
BLAKE2b-256 checksum
How to use checksums
8c0bc60426ed31c2487560bc921e5420235e218067eacf2e694b853bd2968e44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2026.

Transparency log

Release files / assertllm-0.3.1-py3-none-any.whl

Download URL assertllm-0.3.1-py3-none-any.whl
Size 43.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1870a10fd27ef05a688e38ebd73b3766fe790b3ebe10f9383a7de0b2b21916b9
BLAKE2b-256 checksum
How to use checksums
cda01fe8cf7f355d98f825b5607052962006c83a136dd69af303788b0b3b65a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

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