Skip to main content

pytest-llm-confidence

Fail a test when the model wasn't sure of its answer.

Most LLM test tools ask a second model to judge the first, which costs money, adds latency and changes from run to run. pytest-llm-confidence reads the model's own token probabilities instead: no judge model, no extra API cost, and the same response always gets the same verdict.

$ pip install pytest-llm-confidence
# test_answers.py
def test_capital(llm_confidence):
    ans = llm_confidence.ask("What is the capital of Australia? Answer with one word.")
    assert ans.text == "Canberra"
    llm_confidence.assert_confident(ans)          # fails if any word was below 80%
$ pytest
...
FAILED test_answers.py::test_capital - ShakyAnswerError: model wasn't sure of its answer
  (shaky: 1 word(s) below 80%: "Syd" at 41%)
answer: 'Sydney'
  "Syd" at 41%   (alternatives: "Can" 38%)

============================ LLM confidence ============================
SHAKY test_answers.py::test_capital  lowest "Syd" at 41%
1 check(s), 1 shaky

(Illustrative output; real numbers depend on your model.)

Works with your model

  • Ollama 0.12+ (default): llm_confidence.ask talks to http://127.0.0.1:11434.
  • Any OpenAI-compatible server that returns logprobs: OpenAI, vLLM, llama.cpp, LM Studio: pytest --llm-confidence-api openai --llm-confidence-base-url http://127.0.0.1:8000/v1 --llm-confidence-model my-model
  • Responses you already have: assert_confident(response) accepts OpenAI-style responses requested with logprobs=True, Ollama responses requested with "logprobs": true, or (token, logprob) pairs.
from pytest_llm_confidence import assert_confident

def test_my_pipeline():
    response = my_app.call_model("...", logprobs=True)
    assert_confident(response, threshold=0.9)

Settings

Option ini key Default
--llm-confidence-threshold llm_confidence_threshold 0.8
--llm-confidence-model llm_confidence_model llama3.2
--llm-confidence-api llm_confidence_api ollama
--llm-confidence-base-url llm_confidence_base_url $OLLAMA_HOST or http://127.0.0.1:11434
--llm-confidence-double-check llm_confidence_double_check off
--llm-confidence-strict llm_confidence_strict off (skip when the server is down)
--llm-confidence-report PATH llm_confidence_report none (writes JSON for CI artifacts)

Per test: @pytest.mark.llm_confidence(threshold=0.95, double_check=True).

CI-safe by default: if the model server can't be reached, llm_confidence.ask skips the test instead of failing it. Pass --llm-confidence-strict to make that a failure.

Double-check: with double_check=True, a shaky short answer is re-asked in full and ans.double_check.agrees tells you whether the answer held up.

Testing without a model

proprioceptive_confidence.testing.FakeModelServer serves scripted token probabilities over Ollama's and OpenAI's APIs, so you can test your confidence handling in CI without a GPU.

What it can't do

A model can be wrong and certain. This plugin catches shaky answers, not confident mistakes, so keep your correctness assertions too.

  • proprioceptive-confidence: the library this plugin uses, with LangChain and LiteLLM adapters.
  • proprioceptive-mcp: let Claude Code, Cursor and other agents ask your local model and see how sure it was.
  • Proprioceptive Lens: see every word's confidence live in a local app: pip install proprioceptive-lens.

MIT licensed. From Proprioceptive AI.

Metadata

Release files for pytest-llm-confidence 0.1.0

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

Source distribution (sdist)

Source distribution for pytest-llm-confidence 0.1.0
File Size Uploaded Provenance Actions
pytest_llm_confidence-0.1.0.tar.gz 8.5 kB With provenance Details for pytest_llm_confidence-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-llm-confidence 0.1.0
File Interpreter ABI Platform Actions
pytest_llm_confidence-0.1.0-py3-none-any.whl Python 3 none any Details for pytest_llm_confidence-0.1.0-py3-none-any.whl

Total release size: 16.4 kB

Release files / pytest_llm_confidence-0.1.0.tar.gz

Download URL pytest_llm_confidence-0.1.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1ecd1017f150bfb4a53ee27348ca92bb96b7ff76c1d8c03884c976e872203663
BLAKE2b-256 checksum
How to use checksums
8a0c6158d6153f13d593b57b5b8d18fd1266774d91dcf8a157e211b8166916a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 4, 2026.

Transparency log

Release files / pytest_llm_confidence-0.1.0-py3-none-any.whl

Download URL pytest_llm_confidence-0.1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84da947862baf14187e8a1383bf05462944d77d81b0a52851474f93b0d573770
BLAKE2b-256 checksum
How to use checksums
21853f1be3b3608f0a34e712fcdd1c00803a95117380e76ec121b555b5c9fd61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Dec 4, 2026.

Transparency log

Security for pytest-llm-confidence 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_llm_confidence-0.1.0.tar.gz

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 Dec 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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