WebAI Studio

The Classifier API (window.Classifier) evaluates input text against a caller-defined schema of structured questions (binary, categorical, and ordinal) on the user's device, returning a selected option label, confidence score, and probability distribution for each question.

Enable #classifier-api in chrome://flags to use this API.

Use cases

Intent & action routing

Map a user's natural-language input or support request to a predefined set of application actions, departments, or UI filters.

Pre-send checks & moderation

Evaluate drafts or comments locally against boolean criteria (such as policy checks or tone checks) before submitting or escalating to a generative model.

Ordinal rating & ranking

Score items along an ordered scale (such as 1 to 5 severity or relevance) and read the expected value expectedScore.

Question types

A schema passed to Classifier.create() contains a questions array. Each question specifies an id, a prompt, and one of three type values:

TypeOptions RequiredOutput Fields
binaryNo (implicit "true" / "false")Returns label ("true" or "false"), probability, confidence, and probabilities.
categoricalYes (2 or more { label, description } items)Returns the top option label, confidence, and probabilities across all options.
ordinalYes (ordered levels, e.g., "1" through "5")Returns label, expectedScore (weighted average across levels), standardError, confidence, and probabilities.

Classifier.availability()

Checks whether the browser supports creating a classifier session for the given options.

staticavailability(options?: ClassifierCreateOptions): Promise<Availability>;

Returns

A promise that resolves to an Availability string: 'available', 'downloadable', 'downloading', or 'unavailable'.

Interactive Playground

Classifier.create()

Creates a new Classifier instance configured with the provided question schema.

staticcreate(options: ClassifierCreateOptions): Promise<Classifier>;
Interactive Playground

classifier.classify()

Evaluates the input string against all questions defined in the session schema and returns a ClassifierResult.

classify(input: DOMString, options?: ClassifierClassifyOptions): Promise<ClassifierResult>;
Interactive Playground

Decision properties (ClassifierDecision)

PropertyTypeDescription
idDOMStringThe question identifier defined in the schema.
labelDOMStringThe highest-probability option label ("true"/"false" for binary, or one of the supplied options).
confidencedouble (0.0 – 1.0)Confidence score for the decision.
probabilitydouble? (0.0 – 1.0)Present for binary questions: probability of "true".
expectedScoredouble?Present for ordinal questions: weighted average across the ordered option levels.
standardErrordouble?Optional standard error around expectedScore.
probabilitiessequence<OptionProbability>List of { label, probability } entries across all options for the question.

classifier.destroy()

Releases the resources associated with the classifier session when it is no longer needed.

Interactive Playground

API reference (Prospective WebIDL)

Example Output