Skip to main content

The pytest for LLMs — fast, Pydantic-based assertions for AI applications

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assertllm-0.3.1.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

assertllm-0.3.1-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file assertllm-0.3.1.tar.gz.

File metadata

  • Download URL: assertllm-0.3.1.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for assertllm-0.3.1.tar.gz
Algorithm Hash digest
SHA256 a0d4e5053a74676050240ddd0580b187892c00095b26f36b56253ff8cdd3f50c
MD5 eba06856154980354d578dfde1e5d14d
BLAKE2b-256 8c0bc60426ed31c2487560bc921e5420235e218067eacf2e694b853bd2968e44

See more details on using hashes here.

Provenance

The following attestation bundles were made for assertllm-0.3.1.tar.gz:

Publisher: publish.yml on bahadiraraz/LLMTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file assertllm-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: assertllm-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 43.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for assertllm-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1870a10fd27ef05a688e38ebd73b3766fe790b3ebe10f9383a7de0b2b21916b9
MD5 cf52b1bbdd9dde2a3ddf4e95c1d08c0e
BLAKE2b-256 cda01fe8cf7f355d98f825b5607052962006c83a136dd69af303788b0b3b65a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for assertllm-0.3.1-py3-none-any.whl:

Publisher: publish.yml on bahadiraraz/LLMTest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page