Abstention Classifier
The AbstentionClassifier in deepeval is a categorical LLM-as-a-judge that determines whether your LLM application said it did not know when the answer was absent from the provided context, answered from context that supported it, or fabricated one.
A good dataset for this includes some deliberately unanswerable questions, with retrieval_context populated so the judge can see what information the application actually had to work with.
Labels
abstained: the provided context does not contain the answer and the response says so instead of answering.answered: the provided context contains the answer and the response gives it.fabricated: the provided context does not contain the answer but the response gives one anyway.
Usage
Populate retrieval_context (or context) so the judge can tell whether the answer was available.
from deepeval.classifiers import AbstentionClassifier
from deepeval.test_case import LLMTestCase
from deepeval import evaluate
classifier = AbstentionClassifier()
test_case = LLMTestCase(
input="What is the refund window for enterprise plans?",
actual_output="I don't have that information in our policy documents. Please contact your account manager.",
retrieval_context=["Standard plans can be refunded within 30 days of purchase."],
expected_labels={classifier.name: "abstained"},
)
evaluate(test_cases=[test_case], classifiers=[classifier])There are FIVE optional parameters when creating a AbstentionClassifier:
- [Optional]
model: a string specifying which of OpenAI's GPT models to use, OR any custom LLM model of typeDeepEvalBaseLLM. Defaulted togpt-5.4. - [Optional]
include_reason: a boolean which when set toTrue, includes a reason for the chosen label. Defaulted toTrue. - [Optional]
allow_none: a boolean which when set toTrue, lets the classifier return no label when none of them fit (surfaced aslabel=None, with a reason). WhenFalse, the closest label is always chosen. Defaulted toFalse. - [Optional]
async_mode: a boolean which when set toTrue, enables concurrent execution within theclassify()method. Defaulted toTrue. - [Optional]
classification_template: a subclass ofClassifierTemplateused to override the default prompts. Defaulted toClassifierTemplate.
As a standalone
You can also run the AbstentionClassifier on a single test case as a standalone, one-off execution. classify() returns the label and stores the result on the instance:
...
label = classifier.classify(test_case)
print(classifier.label, classifier.reason)How Is It Calculated?
The AbstentionClassifier is a one-shot LLM-as-a-judge: a single call to your evaluation model with the test case content and the labels above, returning the chosen label and a reason. The result is compared against the test case's expected_labels entry, if any, to decide pass or fail.