Skip to main content

Artefactual

Detect hallucinations in language model answers, from their token probabilities.

Tests Docs PyPI License: MIT Python Paper

Artefactual is a Python library that estimates how likely a language model's answer is to be a hallucination. A model that makes something up tends to hesitate while writing it. Artefactual measures that hesitation in the token probabilities returned with the answer, and turns it into a probability, for the whole answer and for each token.

The model was asked It answered P(hallucination)
What is the capital city of France? Paris. 0.08
Who is Charles Moslonka? Where was he born? Charles Moslonka is a French singer born in Lyon in 1985. 0.99

The second answer is invented: Charles Moslonka is the first author of the paper behind this library. The example notebook reproduces both scores.

  • One answer is enough. Scoring needs no second generation, no judge model and no reference documents.
  • It works through an API. It reads the logprobs an OpenAI-compatible endpoint returns, not the weights or hidden states of the model.
  • Trained detectors are published for four open models. You can train one for another model on labelled answers.
  • It is scikit-learn. Detectors have fit and predict_proba, and fit into pipelines and GridSearchCV.

A score measures the model's uncertainty, not the truth of its answer: see the limitations.

pip install artefactual

Quick start

from openai import OpenAI

from artefactual import EPR, WEPR, LogProbParser

K = 15  # the k the published detectors were trained with: request this many top_logprobs
MODEL = "mistralai/Ministral-8B-Instruct-2410"  # the model being scored
DETECTOR = "artefactory/wepr-ministral"  # the detector trained for it

client = OpenAI(base_url="https://your-provider.example/v1")  # any OpenAI-compatible endpoint
response = client.chat.completions.create(
    model=MODEL,
    messages=[{"role": "user", "content": "Who wrote the Rust book?"}],
    logprobs=True,
    top_logprobs=K,
)

logprobs = LogProbParser(k=K).transform(response)  # the response as a logprob array
detector = WEPR.from_pretrained(DETECTOR)
print(detector.predict_proba(logprobs)[:, 1])  # P(hallucination) per sequence
print(detector.predict_token_proba(logprobs))  # ...and per token

A detector is trained for one model, so DETECTOR must be the one published for whatever produced the response — see published detectors for the pairs. There is no default threshold; choosing one is covered in the user guide.

No endpoint is needed to try the library: two of the example notebooks run against checked-in fixtures and need no GPU and no API key. Training a detector for a model with no published weights is covered, with three more notebooks, in training a detector.

Requirements

A response is the result of a call to an OpenAI-compatible API (chat completions, Responses API or batch output). Two conditions apply to the call that produced it:

  1. logprobs and top_logprobs are enabled. Providers that do not expose them cannot be scored at all.
  2. top_logprobs equals the detector's k, as set out in the k rule.

Neither needs auditing in advance — a response that fails one is refused by name.

Installation

pip install artefactual

Two optional extras are available: [adapters] installs langfuse and openai for the integration examples, and [docs] installs Sphinx and the theme for building the documentation.

From source

git clone https://github.com/artefactory/artefactual
cd artefactual
uv sync

Usage

Two classifiers are provided. WEPR fits 2k coefficients and is the more accurate; EPR fits a single coefficient instead, for when labelled data is scarce. They score logprob arrays, which LogProbParser(k=K).transform(responses) makes from completion responses. EPR(k=K) pins the width it accepts and refuses an array of another k; WEPR reads its width from the data. EPR, WEPR and EntropyTransformer run scikit-learn's own estimator checks with no expected failure: see the scikit-learn compatibility guide.

from sklearn.ensemble import RandomForestClassifier

from artefactual import EPR, WEPR, LogProbParser, make_detector

K = 15  # the k the published detectors were trained with

X = LogProbParser(k=K).transform(responses)  # logprob arrays, shaped (n_sequences, n_tokens, K)

# Published weights, end to end: responses in, scores out
detector = make_detector(k=K, classifier=WEPR.from_pretrained("artefactory/wepr-phi4"))
detector.predict_proba(responses)[:, 1]
detector.predict_token_proba(responses)  # per-token scores

# Published weights, or your own file, are loaded rather than fitted: they predict, they do not tune
WEPR.from_pretrained("artefactory/wepr-phi4").predict_proba(X)[:, 1]
EPR.from_pretrained("artefactory/epr-phi4", k=K).predict_proba(X)[:, 1]  # the single-coefficient variant
WEPR.from_pretrained("/path/to/my_detector.skops").predict_proba(X)[:, 1]

# Train one; y is 0/1 per sequence, 1 marking a hallucination
epr = EPR(k=K, estimator=RandomForestClassifier()).fit(X, y)
epr.predict_token_proba(X)  # per-token scores
epr.save_pretrained("my_detector.skops")

# Train the default pipeline, from responses to scores
make_detector(k=K).fit(responses, y)

make_pipeline (for other steps), GridSearchCV and custom detectors are the advanced usage.

Scoring a batch, reading per-token scores, scoring Langfuse traces, tuning with GridSearchCV and training a detector for a model that is not shipped are covered in the user guide.

Published detectors

A detector is named by its own Hugging Face repository, not by the model it scores. Pick the row for the model that produced the responses, and the column for the pooling:

Model that produced the responses EPR WEPR
mistralai/Ministral-8B-Instruct-2410 artefactory/epr-ministral artefactory/wepr-ministral
mistralai/Mistral-Small-3.1-24B-Instruct-2503 artefactory/epr-mistral-small artefactory/wepr-mistral-small
tiiuae/Falcon3-10B-Instruct artefactory/epr-falcon3 artefactory/wepr-falcon3
microsoft/phi-4 artefactory/epr-phi4 artefactory/wepr-phi4

All are trained at k = 15. Both classes also accept a path to a .skops file, so a detector you trained yourself is named the same way one published here is — the package holds no list of models, and publishing another detector needs no release.

Limitations

  • Not every provider can be scored. The requirements above rule out any provider that hides logprobs, and any that caps top_logprobs below the detector's k.
  • Detectors are model-specific. Scoring a model that is not shipped requires training a detector for it, which requires labelled data.
  • The probability is only as good as its training data. Rankings transfer more readily than absolute values.
  • It measures uncertainty, not truth. A model that is confidently wrong is not uncertain, and scores low. This complements retrieval grounding or a judge rather than replacing either.
  • Scoring is per sequence. There is no cross-response consistency check.

Results

ROC-AUC on TriviaQA hallucination detection at k = 15, as reported in Table 1 of the paper:

Model SelfCheckGPT EPR HalluDetect WEPR
Mistral-Small-3.1-24B 79.0 74.6 78.7 82.0
Falcon-3-10B 70.1 75.4 79.0 84.1
Phi-4 (14.7B) 71.4 78.2 83.8 85.4
Ministral-8B-2410 81.1 81.4 86.1 85.8

The full tables and the procedure that produced them are in the scripts/ecir subdirectory.

Documentation

Development

Contributions are welcome — see CONTRIBUTING.md.

uv sync
uv run pytest tests        # test suite (uv sync resolves the env first)
uv run pytest tests --cov  # with coverage

uvx ruff check src tests   # lint — a standalone tool, no project env needed
uvx ruff format src tests
uvx --from shellcheck-py shellcheck scripts/ecir/*.sh

Versioning

Releases are dated (YYYY.MM.PATCH). Breaking changes to the public surface are called out in the release notes.

Citation

If artefactual is useful in your research, please cite the ECIR 2026 paper:

@inproceedings{moslonka2026learned,
  title     = {Learned Hallucination Detection in Black-Box LLMs Using Token-Level Entropy Production Rate},
  author    = {Moslonka, Charles and Randrianarivo, Hicham and Garnier, Arthur and Malherbe, Emmanuel},
  booktitle = {Advances in Information Retrieval},
  series    = {Lecture Notes in Computer Science},
  volume    = {16483},
  pages     = {115--130},
  publisher = {Springer, Cham},
  year      = {2026},
  doi       = {10.1007/978-3-032-21289-4_8},
}

License

MIT — no limitation of usage, including for commercial applications.

Metadata

Release files for artefactual 2026.11.2

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

Source distribution (sdist)

Source distribution for artefactual 2026.11.2
File Size Uploaded Provenance Actions
artefactual-2026.11.2.tar.gz 110.0 kB With provenance Details for artefactual-2026.11.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for artefactual 2026.11.2
File Interpreter ABI Platform Actions
artefactual-2026.11.2-py3-none-any.whl Python 3 none any Details for artefactual-2026.11.2-py3-none-any.whl

Total release size: 160.4 kB

Release files / artefactual-2026.11.2.tar.gz

Download URL artefactual-2026.11.2.tar.gz
Size 110.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4e7dbdab5249a54876282a57d9bcfb2d4ff1a214497c9085d6e3f6e469d662b2
BLAKE2b-256 checksum
How to use checksums
5502418c4cf2e06b99e676d96b382a19f06c7b36dfd85b8aa1aa48fadead61a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Nov 28, 2026.

Transparency log

Release files / artefactual-2026.11.2-py3-none-any.whl

Download URL artefactual-2026.11.2-py3-none-any.whl
Size 50.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
affb0cf15837aaba3b19750c20542af417b5f8a2b4423479f9995525bd8776b9
BLAKE2b-256 checksum
How to use checksums
148d7da4c7e343a892711de1a7142fbae1c7c1b4d120b0654daa8392cea541f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Nov 28, 2026.

Transparency log

Security for artefactual 2026.11.2

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 artefactual-2026.11.2.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 Nov 28, 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.

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