mastra-evals
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Measure Mastra agent and workflow quality with scorers: the built-in LLM judges and code scorers in @mastra/evals, zero-LLM Quick Checks, custom scorers built with createScorer, live scoring with sampling and eligibility filters, runEvals batches, and multi-turn and memory-aware evals. Use this skill whenever the user wants to evaluate, grade, judge, or test an agent's answers, add scorers to an agent or workflow step, write an LLM-as-judge, check tool calls, or score conversations. Triggers on @mastra/evals, @mastra/core/evals, createScorer, runEvals, checks.calledTool, checks.includes, createAnswerRelevancyScorer, createFaithfulnessScorer, createHallucinationScorer, createToxicityScorer, createRubricScorer, createMultiTurnJudgeScorer, createTrajectoryAccuracyScorerCode, notScorable, filterRun, scorers sampling, mastra_scorers. Also triggers when the user asks how to know whether an agent is any good, even if they never say eval or scorer.
- Reads credentials
- Installs packages
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-build-playbookSkill
- mastra-channelsSkill
- mastra-classifierSkill
- mastra-cli-apiSkill
- mastra-client-sdkSkill
- mastra-datasets-experimentsSkill
- mastra-deploymentSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-schedulesSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-signalsSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 94
Verify the API: If node_modules/@mastra/ exists, read node_modules/@mastra/evals/dist/docs/ and node_modules/@mastra/core/dist/docs/ plus …
- Distinctive: line 133
If trace sampling dropped the trace, live scorers skip the run.
- Very specific: line 146
Setting
outputSchemaon a prompt-objectgenerateScore: Not allowed. Only preprocess and analyze take one.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra Evals
Score agent and workflow output with scorers: built-in LLM judges, deterministic Quick Checks, and your own createScorer pipelines, run live or in batches with runEvals.
When to use
- Picking built-in scorers for relevancy, faithfulness, hallucination, toxicity, bias, tool use, or trajectories
- Writing a custom scorer (rule-based, LLM judge, or mixed) with
createScorer - Adding live scoring to an agent or workflow step, with sampling and eligibility filters
- Asserting tool calls or text content with Quick Checks (
checks.*) - Running a batch of inputs through an agent with
runEvals - Evaluating multi-turn conversations or memory-enabled agents
- Making scores persist so they show up in Studio
When NOT to use
- Stored datasets, experiments, comparing runs, CI gates, Vitest matchers (use
mastra-datasets-experiments) - Traces, spans, logs, metrics, user feedback (use
mastra-observability) - Reviewing scores and running experiments in the Studio UI (use
mastra-studio-editor) - Blocking bad input or output at runtime (use
mastra-processors-guardrails) - Classifying text into labels outside of scoring (use
mastra-classifier) - Defining the agent itself (use
mastra-agents) - Memory and thread setup (use
mastra-memory)
Required inputs
- The target: an agent or workflow registered on
new Mastra({...}) - What "good" means: one sentence per quality dimension (correct, grounded, safe, used the right tool)
- Whether each dimension is deterministic (Quick Check or code scorer) or needs judgment (LLM judge)
- The judge model as a
provider/modelstring, ideally from a different provider than the agent - Live or offline: sampling rate for production, or a list of test inputs with optional
groundTruth - Whether the agent uses memory (thread-scoped memory needs a thread per eval)
The framework: scorer, pipeline, runner
A scorer is a MastraScorer. Every scorer, built-in or custom, runs the same four-step pipeline:
preprocess(optional): extract or normalize dataanalyze(optional): gather evidencegenerateScore(required): return a numbergenerateReason(optional): explain the score
Each step is a function (deterministic, no LLM call) or a prompt object (description + createPrompt, plus outputSchema for preprocess/analyze) that calls the judge.
// src/mastra/scorers/quote-sources.ts
import { createScorer } from '@mastra/core/evals'
import { z } from 'zod'
export const quoteSourcesScorer = createScorer({
id: 'quote-sources',
description: 'Check if the response includes sources',
judge: { model: 'openai/gpt-6-luna', instructions: 'You are a strict evaluator.' },
})
.analyze({
description: 'Detect whether sources are present',
outputSchema: z.object({ hasSources: z.boolean(), sources: z.array(z.string()) }),
createPrompt: ({ run }) => `Does the response contain sources? Extract them.\n\n${run.output}`,
})
.generateScore(({ results }) => (results.analyzeStepResult.hasSources ? 1 : 0))Three ways to run scorers:
| Runner | How | Use for |
| Live | scorers: { name: { scorer, sampling } } on an Agent or createStep | Production monitoring, async, non-blocking |
| Batch | runEvals({ target, data, scorers }) from @mastra/core/evals | Local checks, CI scripts, multi-turn |
| Direct | scorer.run({ input, output, groundTruth }) | Unit-testing a scorer |
Scores land in the mastra_scorers table only when the Mastra instance has storage and the scorer is registered (see Deep dive: persistence).
Workflow
- Verify the API. If
node_modules/@mastra/exists, readnode_modules/@mastra/evals/dist/docs/andnode_modules/@mastra/core/dist/docs/plus the installed types. Otherwise fetchhttps://mastra.ai/docs/evals/overview.md,https://mastra.ai/reference/evals/create-scorer.md, andhttps://mastra.ai/reference/evals/run-evals.md. Trust these over memory. - Install.
npm install @mastra/evals@latest.createScorer,runEvals,filterRun, andnotScorablecome from@mastra/core/evals. Built-ins come from@mastra/evals/scorers/prebuilt, checks from@mastra/evals/checks, helpers from@mastra/evals/scorers/utils. - Map each quality dimension to a scorer. Deterministic first: Quick Checks for tool calls and text, code scorers for trajectories. Then LLM judges for semantics (see
references/api.mdfor the full built-in list). - Write custom scorers in
src/mastra/scorers/. Usetype: 'agent'for agent targets sorun.inputandrun.outputare typed and the scorer also works on traces. - Anchor judge scales. In a prompt-object
generateScore, name both endpoints and at least one middle value. Clamp in a function step if the range must hold. - Skip irrelevant runs. Return
notScorable('reason')from a function step (usuallypreprocess) instead of scoring 0. - Register scorers on
new Mastra({ scorers: {...}, storage })so scores persist and appear in Studio. - Attach live scorers to the agent or step with
sampling: { type: 'ratio', rate }. Add afilterto target a segment. - Run a batch with
runEvals, resolving the target throughmastra.getAgent()ormastra.getWorkflow(). - Read scores and reasons, not only averages. Move stable checks into CI (see
mastra-datasets-experiments).
Deep dive: live scoring and persistence
import { Agent } from '@mastra/core/agent'
import { createAnswerRelevancyScorer, createToxicityScorer } from '@mastra/evals/scorers/prebuilt'
export const evaluatedAgent = new Agent({
id: 'evaluated-agent',
name: 'Evaluated Agent',
instructions: 'Answer product questions.',
model: 'openai/gpt-6.1-sol',
scorers: {
relevancy: {
scorer: createAnswerRelevancyScorer({ model: 'openai/gpt-6-luna' }),
filter: { op: 'eq', left: { path: 'requestContext.plan' }, right: { literal: 'enterprise' } },
sampling: { type: 'ratio', rate: 0.1 },
},
safety: {
scorer: createToxicityScorer({ model: 'openai/gpt-6-luna' }),
sampling: { type: 'ratio', rate: 1 },
},
},
})- Sampling is deterministic per trace ID (or run ID without tracing). Scorers at the same rate score the same traces.
- If trace sampling dropped the trace, live scorers skip the run.
filterruns before sampling. It can readrequestContext.*,entity.*,entityType,source,threadId,resourceId,projectId. It cannot see input or output.- Attached scorers register themselves. Scorers passed straight to
runEvals(including checks) must also be listed innew Mastra({ scorers }), or each save logsScorer with id <id> not found. - Lookup is by ID only. One registered
checks.calledTool('get_weather')covers everycheck-called-tooluse.
Failure patterns
- Scores never appear in Studio. No
storage, or the scorer is not innew Mastra({ scorers }). Register it (any config with the same ID works). - Importing the agent directly into
runEvals. Registry lookups fail, scores do not persist, trace trajectories are unavailable. Usemastra.getAgent('id')ormastra.getWorkflow('id'). - Judge returns 1 to 10. Mastra stores the number unclamped, so thresholds between 0 and 1 always pass. Ask for 0 to 1 with anchored descriptions.
- Prompt says "return only the number". The step already requests
{ score: number }. Remove output-format instructions fromgenerateScoreprompts. - Setting
outputSchemaon a prompt-objectgenerateScore. Not allowed. Onlypreprocessandanalyzetake one. - Scoring 0 when the scorer does not apply. Drags averages down. Return
notScorable()from a function step. - Prebuilt judges on multi-turn
inputs. They grade only the last assistant message and see only the first user input. UsecreateMultiTurnJudgeScoreror per-turnturns[].scorers. - ObservationalMemory
threadIderror in evals. Thread-scoped memory needs a thread. PasstargetOptions.memoryand create the thread first (seereferences/examples.md). - Same model judges itself. Bias toward its own answers. Use a judge from another provider and keep it fixed across comparisons.
checks.equalsunexpectedly passing. It ignores case by default. Pass{ ignoreCase: false }.createContentSimilarityScorer({ ignoreCase: true })treating whitespace strictly. Passing an options object turns omitted flags tofalse. Set both flags.
Output format
A finished eval delivery contains:
src/mastra/scorers/<scorer-id>.tsfor each custom scorer, exported- Scorers registered in
src/mastra/index.tsunderscorers, withstorageconfigured - Live scorers attached to the agent or step with an explicit
sampling.rate - A runnable script or test that calls
runEvalsand printsscores,verdict, and failing reasons - The judge model's env var in
.env.example - A short note on what each scorer measures and which direction is better (some are lower-is-better)
Reference files
references/api.md-createScorer, step signatures,runEvalsoptions and results, every built-in scorer and Quick Check, helpers.references/examples.md- Custom judge, Quick Checks plus judge batch, multi-turn conversation, memory-enabled agent.references/checklist.md- Scorer design and rollout checklist.
Live docs
- https://mastra.ai/docs/evals/overview
- https://mastra.ai/docs/evals/built-in-scorers
- https://mastra.ai/docs/evals/custom-scorers
- https://mastra.ai/docs/evals/quick-checks
- https://mastra.ai/docs/evals/evals-with-memory
- https://mastra.ai/docs/evals/multi-turn
- https://mastra.ai/reference/evals/create-scorer
- https://mastra.ai/reference/evals/run-evals
- https://mastra.ai/reference/evals/checks
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

