API reference#

The public surface of artefactual, grouped by role: estimators, transformers, parsing and utilities. A detector is artefactual.EPR or artefactual.WEPR, which score the logprob arrays artefactual.LogProbParser turns responses into; artefactual.make_detector(k=15) chains the two. The other sections are the parts they are made of and the helpers around them.

Estimators#

EPR

Scores logprob arrays with one pooled feature, the Entropy Production Rate.

WEPR

Scores logprob arrays with a mean and a max per rank, the Weighted EPR.

DetectorPipeline

A scikit-learn Pipeline from completion responses to scores, with per-token scores.

Transformers#

scoring.EntropyTransformer

Reduce per-candidate entropy contributions to the features a calibration was fit on.

scoring.epr_reduction

Entropy Production Rate: the truncated entropy, averaged over tokens.

scoring.wepr_reduction

Weighted EPR features: the per-rank mean over tokens, then the per-rank max.

scoring.Pooling

Pools the token axis of NaN-padded entropy contributions; the last axis is ranks.

scoring.EPRPooling

The Entropy Production Rate: one feature, epr_reduction.

scoring.WEPRPooling

The Weighted EPR: a mean and a max per rank, wepr_reduction.

scoring.FunctionPooling

A plain function f(x, axis) as a Pooling, named after the function.

Subclass scoring.Pooling for a pooling of your own, or pass a plain function f(x, axis); either goes to scoring.EntropyTransformer.

Parsing#

LogProbParser, readers and validated models for the response shapes it accepts.

LogProbParser

First pipeline step: completion responses in, a dense logprob array out.

index_by_custom_id

The rows that carry a completion, keyed by the id every stage joins on.

parse_sampled_token_logprobs

Extract the logprob of each sampled token, ignoring the alternatives.

parse_top_logprobs

Extract each token's top-k logprobs, one entry per sampled sequence.

read_batch

Every line of a Batch output file, in file order.

read_judgment

Whether the judge said the answer was CORRECT, or None if its reply cannot be read.

read_message

What the model said, or None if the payload carries no text.

BatchRequestOutput

One line of an OpenAI Batch output file.

BatchResponseData

The response envelope of one Batch output line.

ChatChoice

One sampled sequence of a chat completion.

ChatCompletion

client.chat.completions.create(...) — one choice per sampled sequence.

ChatMessage

The assistant message a chat choice carries.

Judgment

What a judge said about an answer: the verdict, and why.

ResponsesPayload

client.responses.create(...) — one output item per sampled sequence.

Utilities#

Protocols, the per-token score walk and mixins to build on, and the Langfuse integration.

scoring.TokenTransformer

A step that also maps its input to one feature row per token.

scoring.TokenClassifier

A classifier that scores each token of a sequence itself.

scoring.TokenProbaMixin

predict_token_proba for a classifier that builds a fitted pipeline_.

scoring.EntropyContributionsMixin

Provides entropy_contributions to the transformers that reduce it.

scoring.token_proba

Per-token probabilities of class 1 through fitted (name, estimator) steps.

Integrations#

Needs the adapters extra: pip install "artefactual[adapters]".

HallucinationEvaluator

Scores a Langfuse trace's output and writes the result back as a trace score.

Exceptions and warnings#

ArtefactualError

Base for all artefactual errors, so callers can catch the family.

ArtefactualWarning

Base for all artefactual warnings (subclass of UserWarning → shown by default, filterable).

EmptySequenceWarning

A sequence had no tokens; scored at the classifier baseline.