█

AI/TLDR

Buy me a coffee
Buy me a coffee

UQLM

A Python library from CVS Health that detects LLM hallucinations with uncertainty quantification, giving every response a confidence score between 0 and 1

Evaluation & Red-TeamingOpen source
Language
Python
License
Apache-2.0
$pip install uqlm
IN SHORT

What is UQLM?

UQLM (Uncertainty Quantification for Language Models) is an open-source Python library, published by CVS Health, for detecting hallucinations in large language model output. It sits in the Evaluation & Red-Teaming category of the Evaluation & Production Ops tools and is open-source, written in Python and licensed Apache-2.0. To get started: install.

Overview

UQLM (Uncertainty Quantification for Language Models) is an open-source Python library, published by CVS Health, for detecting hallucinations in large language model output. Instead of comparing an answer to a ground truth you rarely have in production, it estimates how uncertain the model was: each scorer returns a confidence score between 0 and 1, where a higher score means a lower likelihood of errors or hallucinations.

Flow diagram: an LLM and three prompts go into uqlm, which outputs each response with a confidence score — Paris 0.93, 2 r's 0.11, Jane Doe 0.27
UQLM takes an LLM and a set of prompts and returns every response alongside a confidence score, so a wrong answer like "2 r's" in strawberry scores low.UQLM README ↗

The scorers come in five families with different cost and compatibility trade-offs. Black-box scorers sample several responses to the same prompt and measure how consistent they are, so they work with any LLM. White-box scorers read token probabilities from a single generation, adding almost no latency or cost but requiring a model that exposes logprobs. LLM-as-a-judge scorers ask one or more judge models to grade the answer. Ensemble scorers combine the others by weighted averaging, either off the shelf or tuned on prompts with known answers. Long-text scorers work at the claim or sentence level and can rewrite a response by dropping low-confidence claims. A separate `CodeGenUQ` interface predicts whether generated code is functionally correct without running it.

Every class takes a LangChain chat model, so the same code runs against OpenAI, Azure OpenAI, Vertex AI, Ollama or any other LangChain-supported provider. The library is Apache-2.0 licensed, installs from PyPI, and is described in a paper in the Journal of Machine Learning Research (2026); the scorer methods and benchmarks are covered in companion papers in TMLR and at EMNLP 2026.

What it does

  • Black-box consistency scorers — discrete semantic entropy, number of semantic sets, non-contradiction and entailment probability, exact match, BERTScore and cosine similarity — that work with any LLM
  • White-box scorers from token probabilities, including minimum token probability, length-normalized sequence probability and probability margin, plus P(True) self-reflection and multi-generation methods such as CoCoA and semantic density
  • LLM-as-a-judge scoring with categorical, continuous or Likert-scale judges, or a panel of several judge models via `LLMPanel`
Black-box scoring diagram: the LLM generates an original response and several candidate responses, pairwise similarity is computed between them, and the result is a confidence score of 0.71
Black-box scorers sample candidate responses and measure how consistent they are with the original answer.
White-box scoring diagram: the answer 'It was George Bush' has token probabilities .92, .99, .99 and .0002, giving a confidence score of 0.11
White-box scorers read token probabilities from a single generation; one improbable token pulls the confidence down.
LLM-as-a-judge diagram: the question and the LLM's answer are concatenated and sent to K judge models, whose correct or incorrect verdicts become numerical scores averaged into a confidence of 0.67
A panel of LLM judges grades the question-answer pair and their verdicts are combined into one confidence score.
  • `UQEnsemble` combines scorers with fixed weights or tunes the weights on prompts with ground-truth answers
  • `LongTextUQ` scores each claim in a long answer and can refine the response by removing claims below a confidence threshold
  • `CodeGenUQ` predicts whether LLM-generated code is functionally correct without executing it

Getting started

UQLM is a pip-installable Python package. Each scorer class wraps a LangChain chat model and exposes an async `generate_and_score` method that returns results you can turn into a DataFrame; `prompts` below is your own list of prompt strings.

Install

The package is published on PyPI and supports Python 3.10 and up.

bashbash
pip install uqlm

Score responses with a black-box scorer

`BlackBoxUQ` samples several responses per prompt and measures their consistency. `use_best=True` returns the uncertainty-minimized response as the answer.

pythonpython
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini")

from uqlm import BlackBoxUQ
bbuq = BlackBoxUQ(llm=llm, scorers=["semantic_negentropy"], use_best=True)

results = await bbuq.generate_and_score(prompts=prompts, num_responses=5)
results.to_df()
DataFrame output from BlackBoxUQ with columns prompt, response, sampled_responses and semantic_negentropy for six math word problems
The results of BlackBoxUQ as a DataFrame: answers whose sampled responses disagree get a low semantic negentropy score.UQLM README ↗

Use token probabilities when your model exposes them

`WhiteBoxUQ` scores a single generation from its token probabilities, with no extra LLM calls for the single-generation scorers.

pythonpython
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model='gemini-2.5-pro')

from uqlm import WhiteBoxUQ
wbuq = WhiteBoxUQ(llm=llm, scorers=["min_probability"])

results = await wbuq.generate_and_score(prompts=prompts)
results.to_df()

Grade answers with a panel of LLM judges

`LLMPanel` sends each question-answer pair to several judge models and aggregates their verdicts into one confidence score.

pythonpython
from langchain_ollama import ChatOllama
llama = ChatOllama(model="llama3")
mistral = ChatOllama(model="mistral")
qwen = ChatOllama(model="qwen3")

from uqlm import LLMPanel
panel = LLMPanel(llm=llama, judges=[llama, mistral, qwen])

results = await panel.generate_and_score(prompts=prompts)
results.to_df()

Tune an ensemble on labelled prompts

`UQEnsemble` mixes black-box, white-box and judge scorers. Use it off the shelf, or tune its weights on prompts with known answers before scoring new ones.

pythonpython
from uqlm import UQEnsemble
scorers = [
    "exact_match", "noncontradiction",  # black-box scorers
    "min_probability",  # white-box scorer
    llm  # use same LLM as a judge
]
uqe = UQEnsemble(llm=llm, scorers=scorers)

tune_results = await uqe.tune(
    prompts=tuning_prompts, ground_truth_answers=ground_truth_answers
)
results = await uqe.generate_and_score(prompts=prompts)
results.to_df()

Score long answers claim by claim

`LongTextUQ` splits each response into claims, scores every claim against sampled responses, and with `response_refinement=True` rebuilds the answer from the claims it keeps.

pythonpython
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o")

from uqlm import LongTextUQ
luq = LongTextUQ(llm=llm, scorers=["entailment"], response_refinement=True)

results = await luq.generate_and_score(prompts=prompts, num_responses=5)
results_df = results.to_df()
Long-text scoring diagram: a response about dolphins is decomposed into claims, one claim is checked for entailment against several sampled responses, and it receives a claim-level confidence score of 0.94
Long-text scorers break an answer into claims and score each one against sampled responses.UQLM README ↗

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Flag low-confidence answers in a production LLM app so they can be withheld, routed to a human or regenerated
  • Pick the most self-consistent of several sampled responses instead of trusting a single generation
  • Strip unsupported claims from long-form answers such as summaries or biographies before they reach a reader
  • Check generated code for likely functional errors without running it, and compare UQ methods on your own data for research

How UQLM compares

UQLM alongside other open-source evaluation & red-teaming tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Strix★ 78.4kStrix runs autonomous AI agents that act like hackers, dynamically running your code to find vulnerabilities and validate them with real proof-of-concepts.
iFixAi★ 47.6kAn agent auditor that runs up to 60 inspections across fabrication, manipulation, deception, unpredictability and opacity, and returns an A–F grade judged by a model from a different vendor.
promptfoo★ 27.9kA developer-first CLI and library for testing and comparing prompts and models, with red-teaming probes for prompt injection, PII leaks, and other vulnerabilities.
OpenAI Evals★ 19.8kA framework and open registry for building and running evaluations of LLMs and LLM-based systems, including prompt chains and tool-using agents.
DeepEval★ 19.7kAn open-source Python framework that tests LLM apps like unit tests, with 50+ metrics for RAG, agents, chatbots, and safety, and a Pytest integration for CI/CD.
Ragas★ 16.5kAn evaluation toolkit focused on retrieval-augmented generation that scores answer faithfulness, context precision/recall, and relevancy, often without needing ground-truth labels.
Arize Phoenix★ 12.5kAn open-source observability and evaluation tool for tracing LLM and agent behavior, running evals on traces, and troubleshooting issues in development and production.
UQLM★ 1.2kA Python library from CVS Health that detects LLM hallucinations with uncertainty quantification, giving every response a confidence score between 0 and 1