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.0.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.0-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: assertllm-0.3.0.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.0.tar.gz
Algorithm Hash digest
SHA256 0efdd9633d3e5651fbdd2955122fd9829ef472a0d7cbeacc72b50ad06bb8d1d8
MD5 6fbbeb73dbb70f161e0e0f6fe2368613
BLAKE2b-256 0e2a1962171f787d470a96eebd23245e11b58b84eda1ec0b4647990e905efe4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for assertllm-0.3.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: assertllm-0.3.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02ddd2f4ede24cfaed88a655790cb6770cf71c3df4d72918b6e53cdef50ccda0
MD5 4799f2979cfb24ffde80e6b141a13ec4
BLAKE2b-256 aa68073db86c31f82fb30ef4031dff8086b73c2df889dab486ad50e9227f3bbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for assertllm-0.3.0-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