Use this file to discover all available pages before exploring further.
Mastra Evals provides a collection of scoring utilities to evaluate AI agent responses. Use prebuilt scorers for common quality metrics or create custom scorers tailored to your needs.
import { createFaithfulnessScorer } from '@mastra/evals/scorers/prebuilt';const faithfulness = createFaithfulnessScorer({ model: 'gpt-4o-mini',});const score = await faithfulness.score({ answer: 'Paris is the capital of France.', context: ['France is a country in Europe', 'Paris is the capital of France'],});console.log(score);// {// value: 1.0,// reason: 'The answer is fully supported by the context'// }
Available LLM Scorers:
createFaithfulnessScorer - Checks if response is supported by context
createAnswerRelevancyScorer - Measures relevance to question
import { createFaithfulnessScorer } from '@mastra/evals/scorers/prebuilt';const scorer = createFaithfulnessScorer({ model: 'gpt-4o-mini' });const testCases = [ { answer: 'Paris is the capital of France', context: ['Paris is the capital of France'], }, { answer: 'London is the capital of France', context: ['Paris is the capital of France'], },];const results = await Promise.all( testCases.map(testCase => scorer.score(testCase)));results.forEach((result, i) => { console.log(`Test ${i + 1}: Score ${result.value}`);});
import { createFaithfulnessScorer, createAnswerRelevancyScorer, createToxicityScorer,} from '@mastra/evals/scorers/prebuilt';const scorers = [ createFaithfulnessScorer({ model: 'gpt-4o-mini' }), createAnswerRelevancyScorer({ model: 'gpt-4o-mini' }), createToxicityScorer({ model: 'gpt-4o-mini' }),];const answer = 'Paris is the capital of France.';const context = ['Paris is the capital of France'];const question = 'What is the capital of France?';const scores = await Promise.all([ scorers[0].score({ answer, context }), scorers[1].score({ answer, question }), scorers[2].score({ answer }),]);console.log('Faithfulness:', scores[0].value);console.log('Relevancy:', scores[1].value);console.log('Toxicity:', scores[2].value);