Overview
A classifier answers typed questions about some state. The state is plain text or structured data, such as a transcript with speaker labels or a screen snapshot. A question is aYesNoQuestion, a ChoiceQuestion among options, or a ScoreQuestion on a scale. Questions are asked by name, several about one state at once, and each gets a typed result with probabilities.
A classifier is a plain object, not a frame processor. Whoever needs answers creates one, keeps it, and calls it. Nothing is added to a pipeline and no frames flow into it. Pipecat components that make small decisions take one as a classifier argument, such as VoicemailDetector and UIWorker.
For a walkthrough, see Pipecat Classifiers.
JevClassifier
Answers through Jev, TypeSafe’s hosted classification model, with calibrated
probabilities.
LLMClassifier
Answers through any Pipecat LLM service that supports
run_inference().Questions
Every field that describes something (instructions, yes, no, an option, a level) takes text, or structured data such as a dict holding the question in one field and what it refers to in others.
YesNoQuestion
Whether the state meets a condition.str | dict[str, Any] | list[Any]
required
What is being checked for, as a yes or no question.
str | dict[str, Any] | list[Any] | None
default:"None"
What counts as a yes, when the question alone leaves it open.
str | dict[str, Any] | list[Any] | None
default:"None"
What counts as a no.
ChoiceQuestion
Which of several options fits the state.str | dict[str, Any] | list[Any]
required
What is being decided.
dict[str, str | dict[str, Any] | list[Any] | None]
required
The options to choose from, each mapped to a description of when it applies,
or
None when the option’s name says enough.ScoreQuestion
Where the state falls on an ordered scale.str | dict[str, Any] | list[Any]
required
What is being rated.
list[str | dict[str, Any] | list[Any]]
required
The levels of the scale in order, lowest first, each described in a few words
or as structured data. At least two.
Results
YesNoResult
The answer to aYesNoQuestion.
ChoiceResult
The answer to aChoiceQuestion.
ScoreResult
The answer to aScoreQuestion.
ScoreResult.probability(level) returns the probability of one level, given as the question gave it, and raises KeyError if the scale has no such level:
ClassifierError
Raised when a classifier cannot answer: the backend failed or did not reply in time, or its reply could not be turned into results. Every classifier answers or raises within a time bound of its own, so a caller waiting on one is never left hanging.BaseClassifier
The base class every classifier extends. It is aBaseObject, so it takes an optional name and supports event handlers.
Methods
ask
questions can mix kinds. Returns one result per question, under the same names, each of the type its question calls for.
yes_no, choice, score
ask() for questions of one kind. They return results already typed, so no isinstance check is needed.
All four raise ClassifierError when the answers could not be produced.
setup
JevClassifier also opens its connection here, so the first question does not pay for it.
cleanup
Properties
Event Handlers
on_metrics
Called after every call with its metrics: aProcessingMetricsData with the time the call took and, when the classifier knows it, an LLMUsageMetricsData with the tokens it used.
MetricsFrame so it reaches the pipeline’s observers like any other metrics:
Writing a Classifier
To back classifiers with another model or service, subclassBaseClassifier and implement _ask(). It receives the state and the questions and returns the results by name, plus the tokens the call used when that is known (or None). Raise ClassifierError when the backend fails. The public methods, typing and metrics are handled by the base class.