Class LlmClassifier

java.lang.Object
com.google.adk.classifiers.LlmClassifier
All Implemented Interfaces:
Classifier

@Experimental public final class LlmClassifier extends Object implements Classifier
Answers typed questions with any BaseLlm through structured output. The model is asked for a probability for every option and constrained to a JSON schema built from the questions, so it can only answer with the given labels. The probabilities are the model's stated values rather than token log-probabilities, so check their calibration with evals before relying on a threshold.
  • Method Details

    • builder

      public static LlmClassifier.Builder builder()
    • name

      public String name()
      Returns the name of the model that answers the questions.
      Specified by:
      name in interface Classifier
    • generateContentConfig

      public Optional<com.google.genai.types.GenerateContentConfig> generateContentConfig()
      Returns the generation settings that every model call starts from, if set.
    • classify

      public io.reactivex.rxjava3.core.Single<ClassifierResponse> classify(ClassifierRequest request)
      Asks the model every question of request in one structured-output call. Choice and score probabilities are clamped at 0 and normalized to sum to 1; a binary probability must lie in [0, 1]. The returned Single fails with IllegalStateException if the model returns no response, reports an error, runs out of output tokens, or answers without a usable probability for every question and option.
      Specified by:
      classify in interface Classifier