Interface Classifier
Classification — a score and/or label, with optional
confidence and metadata. Can be implemented with rules or regex, embeddings, traditional ML, a
small specialised model, a prompted or fine-tuned LLM, or an external classification API — the
implementation is just user code calling out to whatever it needs.
An implementation has a public constructor into which the platform's managed dependencies can
be injected — including a ClassifierClient, for composing other configured classifiers
(for example, an ensemble classifier combining several underlying ones), and a ClassifierContext for the classifier's configured name and config section.
Unlike a Guardrail, a classifier is never bound to a call boundary and is never
dispatched by the runtime. It is invoked inline, wherever a guardrail, an evaluator, or
application code needs it, through an injected ClassifierClient by name.
Classifiers are enabled with configuration; see agent documentation.
-
Method Summary
Modifier and TypeMethodDescriptionClassifiesinputand returns the resultingClassification.default CompletionStage<Classification> classifyAsync(String input) Async variant ofclassify(java.lang.String), for implementations that prefer composing futures.
-
Method Details
-
classify
Classifiesinputand returns the resultingClassification.This is the method to implement. It may block: classifiers are always invoked on virtual threads.
- Returns:
- the classification
-
classifyAsync
Async variant ofclassify(java.lang.String), for implementations that prefer composing futures.The default implementation delegates to
classify(java.lang.String). When this method is overridden,classify(java.lang.String)is no longer used, and it is then safe to have it throwUnsupportedOperationExceptionor returnnull.- Returns:
- a CompletionStage with the classification
-