MastraScorer
The MastraScorer
class is the base class for all scorers in Mastra. It provides a standard .run()
method for evaluating input/output pairs and supports multi-step scoring workflows. Most users will use createScorer
or createLLMScorer
, but advanced users can subclass or instantiate MastraScorer
directly for full control.
Constructor Options
name:
description:
extract:
analyze:
reason:
metadata:
isLLMScorer:
Step Function Signatures
extract
input:
output:
Returns: { results: any }
The method must return an object with a results
property. The value of results
will be passed to the analyze function as extractStepResult
.
analyze
input:
output:
extractStepResult:
Returns: { score: number, results?: any }
The method must return an object with a score
property (required). Optionally, it may return a results
property. The value of results
will be passed to the reason function as analyzeStepResult
.
reason
input:
output:
score:
analyzeStepResult:
extractStepResult:
Returns: { reason: string }
The method must return an object with a reason
property, which should be a string explaining the score.
All step functions can be async.
.run() Input
runId:
input:
output:
additionalContext:
runtimeContext:
.run() Returns
runId:
extractStepResult:
analyzeStepResult:
score:
reason:
Integration
MastraScorer instances can be used for agents and workflow steps