Tone Adherence Classifier
The ToneAdherenceClassifier in deepeval is a categorical LLM-as-a-judge that determines whether your LLM application matched the voice you configured for it.
The tone argument describes that voice. Once it is set, a prompt or model change that shifts how the assistant sounds shows up as a regression rather than slipping through unnoticed.
Labels
on_tone: the response matches the configured tone in wording, register, and length.off_tone: the response departs from the configured tone in wording, register, or length.
Usage
Pass tone to describe the voice the assistant is meant to have; it is folded into the label descriptions.
from deepeval.classifiers import ToneAdherenceClassifier
from deepeval.test_case import LLMTestCase
from deepeval import evaluate
classifier = ToneAdherenceClassifier(tone="warm, plain-spoken, and under three sentences")
test_case = LLMTestCase(
input="My package hasn't arrived.",
actual_output="Sorry about that! I've checked and it's out for delivery today. I'll keep an eye on it for you.",
expected_labels={classifier.name: "on_tone"},
)
evaluate(test_cases=[test_case], classifiers=[classifier])There are SIX optional parameters when creating a ToneAdherenceClassifier:
- [Optional]
tone: a string describing the configured voice, folded into the label descriptions. Defaulted toNone, in which case the judge relies on the test case alone. - [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 ToneAdherenceClassifier 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 ToneAdherenceClassifier 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.