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
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)
| File | Size | Uploaded | |
|---|---|---|---|
| assertllm-0.3.1.tar.gz | 34.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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 logRelease 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