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.

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`



- `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.
pip install uqlmScore 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.
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()
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.
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.
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.
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.
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()
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.
| Tool | Stars | What it does |
|---|---|---|
| Strix | ★ 78.4k | Strix 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.6k | An 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.9k | A 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.8k | A framework and open registry for building and running evaluations of LLMs and LLM-based systems, including prompt chains and tool-using agents. |
| DeepEval | ★ 19.7k | An 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.5k | An 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.5k | An 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.2k | A Python library from CVS Health that detects LLM hallucinations with uncertainty quantification, giving every response a confidence score between 0 and 1 |
