Skip to main content

getClassifier()

The getClassifier() method retrieves a classifier that was registered with the Mastra instance using its registration key. It throws an error if the requested classifier isn't found.

Usage example
Direct link to Usage example

import { mastra } from './mastra'

const safety = mastra.getClassifier('safety')

const result = await safety.evaluate({
state: { content: 'A message to evaluate' },
})

Parameters
Direct link to Parameters

key:

string
The registration key of the classifier to retrieve. This should match a key used when registering classifiers in the Mastra constructor.

Returns
Direct link to Returns

classifier:

Classifier
The Classifier instance associated with the provided key.

Error handling
Direct link to Error handling

This method throws a MastraError with id MASTRA_GET_CLASSIFIER_NOT_FOUND if no classifier is registered under the specified key.

On this page