The pytest for LLMs — fast, Pydantic-based assertions for AI applications
Project description
assertllm
The pytest for LLMs. Test your AI outputs like you test your code.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0d4e5053a74676050240ddd0580b187892c00095b26f36b56253ff8cdd3f50c
|
|
| MD5 |
eba06856154980354d578dfde1e5d14d
|
|
| BLAKE2b-256 |
8c0bc60426ed31c2487560bc921e5420235e218067eacf2e694b853bd2968e44
|
Provenance
The following attestation bundles were made for assertllm-0.3.1.tar.gz:
Publisher:
publish.yml on bahadiraraz/LLMTest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
assertllm-0.3.1.tar.gz -
Subject digest:
a0d4e5053a74676050240ddd0580b187892c00095b26f36b56253ff8cdd3f50c - Sigstore transparency entry: 1068711863
- Sigstore integration time:
-
Permalink:
bahadiraraz/LLMTest@acc76aa36c22b4e00c25e80ecd4824abbfe157f0 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/bahadiraraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@acc76aa36c22b4e00c25e80ecd4824abbfe157f0 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1870a10fd27ef05a688e38ebd73b3766fe790b3ebe10f9383a7de0b2b21916b9
|
|
| MD5 |
cf52b1bbdd9dde2a3ddf4e95c1d08c0e
|
|
| BLAKE2b-256 |
cda01fe8cf7f355d98f825b5607052962006c83a136dd69af303788b0b3b65a9
|
Provenance
The following attestation bundles were made for assertllm-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on bahadiraraz/LLMTest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
assertllm-0.3.1-py3-none-any.whl -
Subject digest:
1870a10fd27ef05a688e38ebd73b3766fe790b3ebe10f9383a7de0b2b21916b9 - Sigstore transparency entry: 1068711904
- Sigstore integration time:
-
Permalink:
bahadiraraz/LLMTest@acc76aa36c22b4e00c25e80ecd4824abbfe157f0 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/bahadiraraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@acc76aa36c22b4e00c25e80ecd4824abbfe157f0 -
Trigger Event:
push
-
Statement type: