@mastra/evals 0.0.0-error-handler-fix-20251020202607 → 0.0.0-execa-dynamic-import-20260304221256

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/CHANGELOG.md +364 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +19 -159
  4. package/dist/chunk-OEOE7ZHN.js +195 -0
  5. package/dist/chunk-OEOE7ZHN.js.map +1 -0
  6. package/dist/{chunk-QKR2PMLZ.cjs → chunk-W3U7MMDX.cjs} +85 -21
  7. package/dist/chunk-W3U7MMDX.cjs.map +1 -0
  8. package/dist/docs/SKILL.md +43 -0
  9. package/dist/docs/assets/SOURCE_MAP.json +6 -0
  10. package/dist/docs/references/docs-evals-built-in-scorers.md +47 -0
  11. package/dist/docs/references/docs-evals-overview.md +141 -0
  12. package/dist/docs/references/reference-evals-answer-relevancy.md +105 -0
  13. package/dist/docs/references/reference-evals-answer-similarity.md +99 -0
  14. package/dist/docs/references/reference-evals-bias.md +120 -0
  15. package/dist/docs/references/reference-evals-completeness.md +136 -0
  16. package/dist/docs/references/reference-evals-content-similarity.md +101 -0
  17. package/dist/docs/references/reference-evals-context-precision.md +196 -0
  18. package/dist/docs/references/reference-evals-context-relevance.md +531 -0
  19. package/dist/docs/references/reference-evals-faithfulness.md +114 -0
  20. package/dist/docs/references/reference-evals-hallucination.md +213 -0
  21. package/dist/docs/references/reference-evals-keyword-coverage.md +128 -0
  22. package/dist/docs/references/reference-evals-noise-sensitivity.md +675 -0
  23. package/dist/docs/references/reference-evals-prompt-alignment.md +614 -0
  24. package/dist/docs/references/reference-evals-scorer-utils.md +326 -0
  25. package/dist/docs/references/reference-evals-textual-difference.md +113 -0
  26. package/dist/docs/references/reference-evals-tone-consistency.md +119 -0
  27. package/dist/docs/references/reference-evals-tool-call-accuracy.md +533 -0
  28. package/dist/docs/references/reference-evals-toxicity.md +123 -0
  29. package/dist/index.cjs +0 -89
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.ts +11 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +0 -86
  34. package/dist/index.js.map +1 -1
  35. package/dist/scorers/code/completeness/index.d.ts +1 -1
  36. package/dist/scorers/code/completeness/index.d.ts.map +1 -1
  37. package/dist/scorers/code/content-similarity/index.d.ts +1 -1
  38. package/dist/scorers/code/content-similarity/index.d.ts.map +1 -1
  39. package/dist/scorers/code/keyword-coverage/index.d.ts +1 -1
  40. package/dist/scorers/code/keyword-coverage/index.d.ts.map +1 -1
  41. package/dist/scorers/code/textual-difference/index.d.ts +1 -1
  42. package/dist/scorers/code/textual-difference/index.d.ts.map +1 -1
  43. package/dist/scorers/code/tone/index.d.ts +1 -1
  44. package/dist/scorers/code/tone/index.d.ts.map +1 -1
  45. package/dist/scorers/code/tool-call-accuracy/index.d.ts +2 -2
  46. package/dist/scorers/code/tool-call-accuracy/index.d.ts.map +1 -1
  47. package/dist/scorers/index.d.ts +1 -0
  48. package/dist/scorers/index.d.ts.map +1 -1
  49. package/dist/scorers/llm/answer-relevancy/index.d.ts +1 -1
  50. package/dist/scorers/llm/answer-relevancy/index.d.ts.map +1 -1
  51. package/dist/scorers/llm/answer-similarity/index.d.ts +2 -2
  52. package/dist/scorers/llm/answer-similarity/index.d.ts.map +1 -1
  53. package/dist/scorers/llm/bias/index.d.ts +2 -2
  54. package/dist/scorers/llm/bias/index.d.ts.map +1 -1
  55. package/dist/scorers/llm/context-precision/index.d.ts +3 -3
  56. package/dist/scorers/llm/context-precision/index.d.ts.map +1 -1
  57. package/dist/scorers/llm/context-relevance/index.d.ts +3 -3
  58. package/dist/scorers/llm/context-relevance/index.d.ts.map +1 -1
  59. package/dist/scorers/llm/faithfulness/index.d.ts +4 -2
  60. package/dist/scorers/llm/faithfulness/index.d.ts.map +1 -1
  61. package/dist/scorers/llm/hallucination/index.d.ts +20 -3
  62. package/dist/scorers/llm/hallucination/index.d.ts.map +1 -1
  63. package/dist/scorers/llm/noise-sensitivity/index.d.ts +1 -1
  64. package/dist/scorers/llm/noise-sensitivity/index.d.ts.map +1 -1
  65. package/dist/scorers/llm/prompt-alignment/index.d.ts +2 -2
  66. package/dist/scorers/llm/prompt-alignment/index.d.ts.map +1 -1
  67. package/dist/scorers/llm/tool-call-accuracy/index.d.ts +3 -3
  68. package/dist/scorers/llm/tool-call-accuracy/index.d.ts.map +1 -1
  69. package/dist/scorers/llm/toxicity/index.d.ts +2 -2
  70. package/dist/scorers/llm/toxicity/index.d.ts.map +1 -1
  71. package/dist/scorers/{llm → prebuilt}/index.cjs +506 -73
  72. package/dist/scorers/prebuilt/index.cjs.map +1 -0
  73. package/dist/scorers/prebuilt/index.d.ts +3 -0
  74. package/dist/scorers/prebuilt/index.d.ts.map +1 -0
  75. package/dist/scorers/{llm → prebuilt}/index.js +446 -26
  76. package/dist/scorers/prebuilt/index.js.map +1 -0
  77. package/dist/scorers/utils.cjs +29 -17
  78. package/dist/scorers/utils.d.ts +375 -12
  79. package/dist/scorers/utils.d.ts.map +1 -1
  80. package/dist/scorers/utils.js +1 -1
  81. package/package.json +22 -64
  82. package/dist/attachListeners.d.ts +0 -4
  83. package/dist/attachListeners.d.ts.map +0 -1
  84. package/dist/chunk-7QAUEU4L.cjs +0 -10
  85. package/dist/chunk-7QAUEU4L.cjs.map +0 -1
  86. package/dist/chunk-EMMSS5I5.cjs +0 -37
  87. package/dist/chunk-EMMSS5I5.cjs.map +0 -1
  88. package/dist/chunk-G3PMV62Z.js +0 -33
  89. package/dist/chunk-G3PMV62Z.js.map +0 -1
  90. package/dist/chunk-IUSAD2BW.cjs +0 -19
  91. package/dist/chunk-IUSAD2BW.cjs.map +0 -1
  92. package/dist/chunk-KHEXN75Q.js +0 -134
  93. package/dist/chunk-KHEXN75Q.js.map +0 -1
  94. package/dist/chunk-QKR2PMLZ.cjs.map +0 -1
  95. package/dist/chunk-QTWX6TKR.js +0 -8
  96. package/dist/chunk-QTWX6TKR.js.map +0 -1
  97. package/dist/chunk-YGTIO3J5.js +0 -17
  98. package/dist/chunk-YGTIO3J5.js.map +0 -1
  99. package/dist/dist-E463LOAZ.js +0 -16729
  100. package/dist/dist-E463LOAZ.js.map +0 -1
  101. package/dist/dist-KKO3PIUK.cjs +0 -16751
  102. package/dist/dist-KKO3PIUK.cjs.map +0 -1
  103. package/dist/evaluation.d.ts +0 -8
  104. package/dist/evaluation.d.ts.map +0 -1
  105. package/dist/magic-string.es-7ORA5OGR.js +0 -1305
  106. package/dist/magic-string.es-7ORA5OGR.js.map +0 -1
  107. package/dist/magic-string.es-NZ2XWFKN.cjs +0 -1311
  108. package/dist/magic-string.es-NZ2XWFKN.cjs.map +0 -1
  109. package/dist/metrics/index.d.ts +0 -4
  110. package/dist/metrics/index.d.ts.map +0 -1
  111. package/dist/metrics/judge/index.cjs +0 -12
  112. package/dist/metrics/judge/index.cjs.map +0 -1
  113. package/dist/metrics/judge/index.d.ts +0 -7
  114. package/dist/metrics/judge/index.d.ts.map +0 -1
  115. package/dist/metrics/judge/index.js +0 -3
  116. package/dist/metrics/judge/index.js.map +0 -1
  117. package/dist/metrics/llm/answer-relevancy/index.d.ts +0 -16
  118. package/dist/metrics/llm/answer-relevancy/index.d.ts.map +0 -1
  119. package/dist/metrics/llm/answer-relevancy/metricJudge.d.ts +0 -20
  120. package/dist/metrics/llm/answer-relevancy/metricJudge.d.ts.map +0 -1
  121. package/dist/metrics/llm/answer-relevancy/prompts.d.ts +0 -19
  122. package/dist/metrics/llm/answer-relevancy/prompts.d.ts.map +0 -1
  123. package/dist/metrics/llm/bias/index.d.ts +0 -14
  124. package/dist/metrics/llm/bias/index.d.ts.map +0 -1
  125. package/dist/metrics/llm/bias/metricJudge.d.ts +0 -14
  126. package/dist/metrics/llm/bias/metricJudge.d.ts.map +0 -1
  127. package/dist/metrics/llm/bias/prompts.d.ts +0 -14
  128. package/dist/metrics/llm/bias/prompts.d.ts.map +0 -1
  129. package/dist/metrics/llm/context-position/index.d.ts +0 -16
  130. package/dist/metrics/llm/context-position/index.d.ts.map +0 -1
  131. package/dist/metrics/llm/context-position/metricJudge.d.ts +0 -20
  132. package/dist/metrics/llm/context-position/metricJudge.d.ts.map +0 -1
  133. package/dist/metrics/llm/context-position/prompts.d.ts +0 -17
  134. package/dist/metrics/llm/context-position/prompts.d.ts.map +0 -1
  135. package/dist/metrics/llm/context-precision/index.d.ts +0 -16
  136. package/dist/metrics/llm/context-precision/index.d.ts.map +0 -1
  137. package/dist/metrics/llm/context-precision/metricJudge.d.ts +0 -20
  138. package/dist/metrics/llm/context-precision/metricJudge.d.ts.map +0 -1
  139. package/dist/metrics/llm/context-precision/prompts.d.ts +0 -17
  140. package/dist/metrics/llm/context-precision/prompts.d.ts.map +0 -1
  141. package/dist/metrics/llm/context-relevancy/index.d.ts +0 -16
  142. package/dist/metrics/llm/context-relevancy/index.d.ts.map +0 -1
  143. package/dist/metrics/llm/context-relevancy/metricJudge.d.ts +0 -16
  144. package/dist/metrics/llm/context-relevancy/metricJudge.d.ts.map +0 -1
  145. package/dist/metrics/llm/context-relevancy/prompts.d.ts +0 -13
  146. package/dist/metrics/llm/context-relevancy/prompts.d.ts.map +0 -1
  147. package/dist/metrics/llm/contextual-recall/index.d.ts +0 -16
  148. package/dist/metrics/llm/contextual-recall/index.d.ts.map +0 -1
  149. package/dist/metrics/llm/contextual-recall/metricJudge.d.ts +0 -16
  150. package/dist/metrics/llm/contextual-recall/metricJudge.d.ts.map +0 -1
  151. package/dist/metrics/llm/contextual-recall/prompts.d.ts +0 -13
  152. package/dist/metrics/llm/contextual-recall/prompts.d.ts.map +0 -1
  153. package/dist/metrics/llm/faithfulness/index.d.ts +0 -16
  154. package/dist/metrics/llm/faithfulness/index.d.ts.map +0 -1
  155. package/dist/metrics/llm/faithfulness/metricJudge.d.ts +0 -22
  156. package/dist/metrics/llm/faithfulness/metricJudge.d.ts.map +0 -1
  157. package/dist/metrics/llm/faithfulness/prompts.d.ts +0 -20
  158. package/dist/metrics/llm/faithfulness/prompts.d.ts.map +0 -1
  159. package/dist/metrics/llm/hallucination/index.d.ts +0 -16
  160. package/dist/metrics/llm/hallucination/index.d.ts.map +0 -1
  161. package/dist/metrics/llm/hallucination/metricJudge.d.ts +0 -22
  162. package/dist/metrics/llm/hallucination/metricJudge.d.ts.map +0 -1
  163. package/dist/metrics/llm/hallucination/prompts.d.ts +0 -17
  164. package/dist/metrics/llm/hallucination/prompts.d.ts.map +0 -1
  165. package/dist/metrics/llm/index.cjs +0 -2481
  166. package/dist/metrics/llm/index.cjs.map +0 -1
  167. package/dist/metrics/llm/index.d.ts +0 -12
  168. package/dist/metrics/llm/index.d.ts.map +0 -1
  169. package/dist/metrics/llm/index.js +0 -2469
  170. package/dist/metrics/llm/index.js.map +0 -1
  171. package/dist/metrics/llm/prompt-alignment/index.d.ts +0 -33
  172. package/dist/metrics/llm/prompt-alignment/index.d.ts.map +0 -1
  173. package/dist/metrics/llm/prompt-alignment/metricJudge.d.ts +0 -20
  174. package/dist/metrics/llm/prompt-alignment/metricJudge.d.ts.map +0 -1
  175. package/dist/metrics/llm/prompt-alignment/prompts.d.ts +0 -17
  176. package/dist/metrics/llm/prompt-alignment/prompts.d.ts.map +0 -1
  177. package/dist/metrics/llm/summarization/index.d.ts +0 -19
  178. package/dist/metrics/llm/summarization/index.d.ts.map +0 -1
  179. package/dist/metrics/llm/summarization/metricJudge.d.ts +0 -34
  180. package/dist/metrics/llm/summarization/metricJudge.d.ts.map +0 -1
  181. package/dist/metrics/llm/summarization/prompts.d.ts +0 -30
  182. package/dist/metrics/llm/summarization/prompts.d.ts.map +0 -1
  183. package/dist/metrics/llm/toxicity/index.d.ts +0 -14
  184. package/dist/metrics/llm/toxicity/index.d.ts.map +0 -1
  185. package/dist/metrics/llm/toxicity/metricJudge.d.ts +0 -14
  186. package/dist/metrics/llm/toxicity/metricJudge.d.ts.map +0 -1
  187. package/dist/metrics/llm/toxicity/prompts.d.ts +0 -10
  188. package/dist/metrics/llm/toxicity/prompts.d.ts.map +0 -1
  189. package/dist/metrics/llm/types.d.ts +0 -7
  190. package/dist/metrics/llm/types.d.ts.map +0 -1
  191. package/dist/metrics/llm/utils.d.ts +0 -14
  192. package/dist/metrics/llm/utils.d.ts.map +0 -1
  193. package/dist/metrics/nlp/completeness/index.d.ts +0 -21
  194. package/dist/metrics/nlp/completeness/index.d.ts.map +0 -1
  195. package/dist/metrics/nlp/content-similarity/index.d.ts +0 -18
  196. package/dist/metrics/nlp/content-similarity/index.d.ts.map +0 -1
  197. package/dist/metrics/nlp/index.cjs +0 -203
  198. package/dist/metrics/nlp/index.cjs.map +0 -1
  199. package/dist/metrics/nlp/index.d.ts +0 -6
  200. package/dist/metrics/nlp/index.d.ts.map +0 -1
  201. package/dist/metrics/nlp/index.js +0 -190
  202. package/dist/metrics/nlp/index.js.map +0 -1
  203. package/dist/metrics/nlp/keyword-coverage/index.d.ts +0 -13
  204. package/dist/metrics/nlp/keyword-coverage/index.d.ts.map +0 -1
  205. package/dist/metrics/nlp/textual-difference/index.d.ts +0 -15
  206. package/dist/metrics/nlp/textual-difference/index.d.ts.map +0 -1
  207. package/dist/metrics/nlp/tone/index.d.ts +0 -18
  208. package/dist/metrics/nlp/tone/index.d.ts.map +0 -1
  209. package/dist/scorers/code/index.cjs +0 -329
  210. package/dist/scorers/code/index.cjs.map +0 -1
  211. package/dist/scorers/code/index.js +0 -315
  212. package/dist/scorers/code/index.js.map +0 -1
  213. package/dist/scorers/llm/index.cjs.map +0 -1
  214. package/dist/scorers/llm/index.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/scorers/utils.ts"],"names":["requestContext","RequestContext"],"mappings":";;;;;AAyBO,SAAS,kCAAkC,OAAA,EAAkC;AAClF,EAAA,IAAI,OAAO,QAAQ,OAAA,CAAQ,OAAA,KAAY,YAAY,OAAA,CAAQ,OAAA,CAAQ,YAAY,EAAA,EAAI;AACjF,IAAA,OAAO,QAAQ,OAAA,CAAQ,OAAA;AAAA,EACzB;AACA,EAAA,I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AA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,KAAA,EAAO,SAAA,EAAW,aAAA,EAAc;AAC3C;AAiBO,IAAM,oBAAA,GAAuB,CAAC,QAAA,KAA2D;AAC9F,EAAA,OAAO,QAAA,EAAU,eAAe,GAAA,CAAI,CAAA,GAAA,KAAO,kCAAkC,GAAG,CAAC,KAAK,EAAC;AACzF;AAmBO,IAAM,4BAAA,GAA+B,CAAC,SAAA,KAAiD;AAC5F,EAAA,OAAO,SAAA,CAAU,MAAA,CAAO,CAAA,GAAA,KAAO,GAAA,CAAI,IAAA,KAAS,WAAW,CAAA,CAAE,GAAA,CAAI,CAAA,GAAA,KAAO,iCAAA,CAAkC,GAAG,CAAC,CAAA;AAC5G;AAyCO,SAAS,mBAAmB,MAAA,EAAmD;AACpF,EAAA,MAAM,UAA4B,EAAC;AAEnC,EAAA,KAAA,MAAW,WAAW,MAAA,EAAQ;AAC5B,IAAA,MAAM,eAAA,GAAkB,SAAS,OAAA,EAAS,eAAA;AAC1C,IAAA,IAAI,CAAC,eAAA,EAAiB;AAEtB,IAAA,KAAA,MAAW,cAAc,eAAA,EAAiB;AACxC,MAAA,IAAI,UAAA,CAAW,KAAA,KAAU,QAAA,IAAY,UAAA,CAAW,WAAW,MAAA,EAAW;AACpE,QAAA,OAAA,CAAQ,IAAA,CAAK;AAAA,UACX,UAAU,UAAA,CAAW,QAAA;AAAA,UACrB,UAAA,EAAY,WAAW,UAAA,IAAc,EAAA;AAAA,UACrC,IAAA,EAAM,UAAA,CAAW,IAAA,IAAQ,EAAC;AAAA,UAC1B,QAAQ,UAAA,CAAW;AAAA,SACpB,CAAA;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,OAAA;AACT","file":"chunk-W3U7MMDX.cjs","sourcesContent":["import type { MastraDBMessage } from '@mastra/core/agent';\nimport type { ScorerRunInputForAgent, ScorerRunOutputForAgent, ScoringInput } from '@mastra/core/evals';\nimport { RequestContext } from '@mastra/core/request-context';\n\n/**\n * Extracts text content from a MastraDBMessage.\n *\n * This function matches the logic used in `MessageList.mastraDBMessageToAIV4UIMessage`.\n * It first checks for a string `content.content` field, then falls back to extracting\n * text from the `parts` array (returning only the last text part, like AI SDK does).\n *\n * @param message - The MastraDBMessage to extract text from\n * @returns The extracted text content, or an empty string if no text is found\n *\n * @example\n * ```ts\n * const message: MastraDBMessage = {\n * id: 'msg-1',\n * role: 'assistant',\n * content: { format: 2, parts: [{ type: 'text', text: 'Hello!' }] },\n * createdAt: new Date(),\n * };\n * const text = getTextContentFromMastraDBMessage(message); // 'Hello!'\n * ```\n */\nexport function getTextContentFromMastraDBMessage(message: MastraDBMessage): string {\n if (typeof message.content.content === 'string' && message.content.content !== '') {\n return message.content.content;\n }\n if (message.content.parts && Array.isArray(message.content.parts)) {\n // Return only the last text part like AI SDK does\n const textParts = message.content.parts.filter(p => p.type === 'text');\n return textParts.length > 0 ? textParts[textParts.length - 1]?.text || '' : '';\n }\n return '';\n}\n\n/**\n * Rounds a number to two decimal places.\n *\n * Uses `Number.EPSILON` to handle floating-point precision issues.\n *\n * @param num - The number to round\n * @returns The number rounded to two decimal places\n *\n * @example\n * ```ts\n * roundToTwoDecimals(0.1 + 0.2); // 0.3\n * roundToTwoDecimals(1.005); // 1.01\n * ```\n */\nexport const roundToTwoDecimals = (num: number) => {\n return Math.round((num + Number.EPSILON) * 100) / 100;\n};\n\n/**\n * Determines if a value is closer to the first target than the second.\n *\n * @param value - The value to compare\n * @param target1 - The first target value\n * @param target2 - The second target value\n * @returns `true` if `value` is closer to `target1` than `target2`\n *\n * @example\n * ```ts\n * isCloserTo(0.6, 1, 0); // true (0.6 is closer to 1)\n * isCloserTo(0.3, 1, 0); // false (0.3 is closer to 0)\n * ```\n */\nexport function isCloserTo(value: number, target1: number, target2: number): boolean {\n return Math.abs(value - target1) < Math.abs(value - target2);\n}\n\n/**\n * Represents a test case for scorer evaluation.\n */\nexport type TestCase = {\n /** The input text to evaluate */\n input: string;\n /** The output text to evaluate */\n output: string;\n /** The expected result of the evaluation */\n expectedResult: {\n /** The expected score */\n score: number;\n /** The optional expected reason */\n reason?: string;\n };\n};\n\n/**\n * Represents a test case with additional context for scorer evaluation.\n */\nexport type TestCaseWithContext = TestCase & {\n /** Additional context strings for the evaluation */\n context: string[];\n};\n\n/**\n * Creates a scoring input object for testing purposes.\n *\n * @param input - The user input text\n * @param output - The assistant output text\n * @param additionalContext - Optional additional context data\n * @param requestContext - Optional request context data\n * @returns A ScoringInput object ready for use in scorer tests\n *\n * @example\n * ```ts\n * const run = createTestRun(\n * 'What is 2+2?',\n * 'The answer is 4.',\n * { topic: 'math' }\n * );\n * ```\n */\nexport const createTestRun = (\n input: string,\n output: string,\n additionalContext?: Record<string, any>,\n requestContext?: Record<string, any>,\n): ScoringInput => {\n return {\n input: [{ role: 'user', content: input }],\n output: { role: 'assistant', text: output },\n additionalContext: additionalContext ?? {},\n requestContext: requestContext ?? {},\n };\n};\n\n/**\n * Extracts the user message text from a scorer run input.\n *\n * Finds the first message with role 'user' and extracts its text content.\n *\n * @param input - The scorer run input containing input messages\n * @returns The user message text, or `undefined` if no user message is found\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const userText = getUserMessageFromRunInput(run.input);\n * return { userText };\n * });\n * ```\n */\nexport const getUserMessageFromRunInput = (input?: ScorerRunInputForAgent): string | undefined => {\n const message = input?.inputMessages.find(({ role }) => role === 'user');\n return message ? getTextContentFromMastraDBMessage(message) : undefined;\n};\n\n/**\n * Extracts all system messages from a scorer run input.\n *\n * Collects text from both standard system messages and tagged system messages\n * (specialized system prompts like memory instructions).\n *\n * @param input - The scorer run input containing system messages\n * @returns An array of system message strings\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemMessages = getSystemMessagesFromRunInput(run.input);\n * return { systemPrompt: systemMessages.join('\\n') };\n * });\n * ```\n */\nexport const getSystemMessagesFromRunInput = (input?: ScorerRunInputForAgent): string[] => {\n const systemMessages: string[] = [];\n\n // Add standard system messages\n if (input?.systemMessages) {\n systemMessages.push(\n ...input.systemMessages\n .map(msg => {\n // Handle different content types - extract text if it's an array of parts\n if (typeof msg.content === 'string') {\n return msg.content;\n } else if (Array.isArray(msg.content)) {\n // Extract text from parts array\n return msg.content\n .filter((part: any) => part.type === 'text')\n .map((part: any) => part.text || '')\n .join(' ');\n }\n return '';\n })\n .filter(content => content),\n );\n }\n\n // Add tagged system messages (these are specialized system prompts)\n if (input?.taggedSystemMessages) {\n Object.values(input.taggedSystemMessages).forEach(messages => {\n messages.forEach(msg => {\n if (typeof msg.content === 'string') {\n systemMessages.push(msg.content);\n }\n });\n });\n }\n\n return systemMessages;\n};\n\n/**\n * Combines all system messages into a single prompt string.\n *\n * Joins all system messages (standard and tagged) with double newlines.\n *\n * @param input - The scorer run input containing system messages\n * @returns A combined system prompt string\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const systemPrompt = getCombinedSystemPrompt(run.input);\n * return { systemPrompt };\n * });\n * ```\n */\nexport const getCombinedSystemPrompt = (input?: ScorerRunInputForAgent): string => {\n const systemMessages = getSystemMessagesFromRunInput(input);\n return systemMessages.join('\\n\\n');\n};\n\n/**\n * Extracts the assistant message text from a scorer run output.\n *\n * Finds the first message with role 'assistant' and extracts its text content.\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns The assistant message text, or `undefined` if no assistant message is found\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { response };\n * });\n * ```\n */\nexport const getAssistantMessageFromRunOutput = (output?: ScorerRunOutputForAgent) => {\n const message = output?.find(({ role }) => role === 'assistant');\n return message ? getTextContentFromMastraDBMessage(message) : undefined;\n};\n\n/**\n * Extracts reasoning text from a scorer run output.\n *\n * This function extracts reasoning content from assistant messages, which is\n * produced by reasoning models like `deepseek-reasoner`. The reasoning can be\n * stored in two places:\n * 1. `content.reasoning` - a string field on the message content\n * 2. `content.parts` - as parts with `type: 'reasoning'` containing `details`\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns The reasoning text, or `undefined` if no reasoning is present\n *\n * @example\n * ```ts\n * const reasoningScorer = createScorer({\n * id: 'reasoning-scorer',\n * name: 'Reasoning Quality',\n * description: 'Evaluates the quality of model reasoning',\n * type: 'agent',\n * })\n * .preprocess(({ run }) => {\n * const reasoning = getReasoningFromRunOutput(run.output);\n * const response = getAssistantMessageFromRunOutput(run.output);\n * return { reasoning, response };\n * })\n * .generateScore(({ results }) => {\n * // Score based on reasoning quality\n * return results.preprocessStepResult?.reasoning ? 1 : 0;\n * });\n * ```\n */\nexport const getReasoningFromRunOutput = (output?: ScorerRunOutputForAgent): string | undefined => {\n if (!output) return undefined;\n\n const message = output.find(({ role }) => role === 'assistant');\n if (!message) return undefined;\n\n // Check for reasoning in content.reasoning (string format)\n if (message.content.reasoning) {\n return message.content.reasoning;\n }\n\n // Check for reasoning in parts with type 'reasoning'\n // Reasoning models store reasoning in parts as { type: 'reasoning', details: [{ type: 'text', text: '...' }] }\n const reasoningParts = message.content.parts?.filter((p: any) => p.type === 'reasoning');\n if (reasoningParts && reasoningParts.length > 0) {\n const reasoningTexts = reasoningParts\n .map((p: any) => {\n // The reasoning text can be in p.reasoning or in p.details[].text\n if (p.details && Array.isArray(p.details)) {\n return p.details\n .filter((d: any) => d.type === 'text')\n .map((d: any) => d.text)\n .join('');\n }\n return p.reasoning || '';\n })\n .filter(Boolean);\n\n return reasoningTexts.length > 0 ? reasoningTexts.join('\\n') : undefined;\n }\n\n return undefined;\n};\n\n/**\n * Creates a tool invocation object for testing purposes.\n *\n * @param options - The tool invocation configuration\n * @param options.toolCallId - Unique identifier for the tool call\n * @param options.toolName - Name of the tool being called\n * @param options.args - Arguments passed to the tool\n * @param options.result - Result returned by the tool\n * @param options.state - State of the invocation (default: 'result')\n * @returns A tool invocation object\n *\n * @example\n * ```ts\n * const invocation = createToolInvocation({\n * toolCallId: 'call-123',\n * toolName: 'weatherTool',\n * args: { location: 'London' },\n * result: { temperature: 20, condition: 'sunny' },\n * });\n * ```\n */\nexport const createToolInvocation = ({\n toolCallId,\n toolName,\n args,\n result,\n state = 'result',\n}: {\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state?: 'call' | 'partial-call' | 'result';\n}): { toolCallId: string; toolName: string; args: Record<string, any>; result: Record<string, any>; state: string } => {\n return {\n toolCallId,\n toolName,\n args,\n result,\n state,\n };\n};\n\n/**\n * Creates a MastraDBMessage object for testing purposes.\n *\n * Supports optional tool invocations for testing tool call scenarios.\n *\n * @param options - The message configuration\n * @param options.content - The text content of the message\n * @param options.role - The role of the message sender ('user', 'assistant', or 'system')\n * @param options.id - Optional message ID (default: 'test-message')\n * @param options.toolInvocations - Optional array of tool invocations\n * @returns A MastraDBMessage object\n *\n * @example\n * ```ts\n * const message = createTestMessage({\n * content: 'Hello, how can I help?',\n * role: 'assistant',\n * });\n *\n * // With tool invocations\n * const messageWithTools = createTestMessage({\n * content: 'Let me check the weather.',\n * role: 'assistant',\n * toolInvocations: [{\n * toolCallId: 'call-1',\n * toolName: 'weatherTool',\n * args: { location: 'Paris' },\n * result: { temp: 22 },\n * state: 'result',\n * }],\n * });\n * ```\n */\nexport function createTestMessage({\n content,\n role,\n id = 'test-message',\n toolInvocations = [],\n}: {\n content: string;\n role: 'user' | 'assistant' | 'system';\n id?: string;\n toolInvocations?: Array<{\n toolCallId: string;\n toolName: string;\n args: Record<string, any>;\n result: Record<string, any>;\n state: any;\n }>;\n}): MastraDBMessage {\n return {\n id,\n role,\n content: {\n format: 2,\n parts: [{ type: 'text', text: content }],\n content,\n ...(toolInvocations.length > 0 && {\n toolInvocations: toolInvocations.map(ti => ({\n toolCallId: ti.toolCallId,\n toolName: ti.toolName,\n args: ti.args,\n result: ti.result,\n state: ti.state,\n })),\n }),\n },\n createdAt: new Date(),\n };\n}\n\n/**\n * Creates a complete agent test run object for testing scorers.\n *\n * Provides a convenient way to construct the full run object that scorers receive,\n * including input messages, output, system messages, and request context.\n *\n * @param options - The test run configuration\n * @param options.inputMessages - Array of input messages (default: [])\n * @param options.output - The output messages (required)\n * @param options.rememberedMessages - Array of remembered messages from memory (default: [])\n * @param options.systemMessages - Array of system messages (default: [])\n * @param options.taggedSystemMessages - Tagged system messages map (default: {})\n * @param options.requestContext - Request context (default: new RequestContext())\n * @param options.runId - Unique run ID (default: random UUID)\n * @returns A complete test run object\n *\n * @example\n * ```ts\n * const testRun = createAgentTestRun({\n * inputMessages: [createTestMessage({ content: 'Hello', role: 'user' })],\n * output: [createTestMessage({ content: 'Hi there!', role: 'assistant' })],\n * });\n *\n * const result = await scorer.run({\n * input: testRun.input,\n * output: testRun.output,\n * });\n * ```\n */\nexport const createAgentTestRun = ({\n inputMessages = [],\n output,\n rememberedMessages = [],\n systemMessages = [],\n taggedSystemMessages = {},\n requestContext = new RequestContext(),\n runId = crypto.randomUUID(),\n}: {\n inputMessages?: ScorerRunInputForAgent['inputMessages'];\n output: ScorerRunOutputForAgent;\n rememberedMessages?: ScorerRunInputForAgent['rememberedMessages'];\n systemMessages?: ScorerRunInputForAgent['systemMessages'];\n taggedSystemMessages?: ScorerRunInputForAgent['taggedSystemMessages'];\n requestContext?: RequestContext;\n runId?: string;\n}): {\n input: ScorerRunInputForAgent;\n output: ScorerRunOutputForAgent;\n requestContext: RequestContext;\n runId: string;\n} => {\n return {\n input: {\n inputMessages,\n rememberedMessages,\n systemMessages,\n taggedSystemMessages,\n },\n output,\n requestContext,\n runId,\n };\n};\n\n/**\n * Information about a tool call extracted from scorer output.\n */\nexport type ToolCallInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Index of the message containing this tool call */\n messageIndex: number;\n /** Index of the invocation within the message's tool invocations */\n invocationIndex: number;\n};\n\n/**\n * Extracts all tool calls from a scorer run output.\n *\n * Iterates through all messages and their tool invocations to collect\n * information about tools that were called (with state 'result' or 'call').\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An object containing tool names and detailed tool call info\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const { tools, toolCallInfos } = extractToolCalls(run.output);\n * return {\n * toolsUsed: tools,\n * toolCount: tools.length,\n * };\n * });\n * ```\n */\nexport function extractToolCalls(output: ScorerRunOutputForAgent): { tools: string[]; toolCallInfos: ToolCallInfo[] } {\n const toolCalls: string[] = [];\n const toolCallInfos: ToolCallInfo[] = [];\n\n for (let messageIndex = 0; messageIndex < output.length; messageIndex++) {\n const message = output[messageIndex];\n // Tool invocations are now nested under content\n if (message?.content?.toolInvocations) {\n for (let invocationIndex = 0; invocationIndex < message.content.toolInvocations.length; invocationIndex++) {\n const invocation = message.content.toolInvocations[invocationIndex];\n if (invocation && invocation.toolName && (invocation.state === 'result' || invocation.state === 'call')) {\n toolCalls.push(invocation.toolName);\n toolCallInfos.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || `${messageIndex}-${invocationIndex}`,\n messageIndex,\n invocationIndex,\n });\n }\n }\n }\n }\n\n return { tools: toolCalls, toolCallInfos };\n}\n\n/**\n * Extracts text content from all input messages.\n *\n * @param runInput - The scorer run input\n * @returns An array of text strings from each input message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const messages = extractInputMessages(run.input);\n * return { allUserMessages: messages.join('\\n') };\n * });\n * ```\n */\nexport const extractInputMessages = (runInput: ScorerRunInputForAgent | undefined): string[] => {\n return runInput?.inputMessages?.map(msg => getTextContentFromMastraDBMessage(msg)) || [];\n};\n\n/**\n * Extracts text content from all assistant response messages.\n *\n * Filters for messages with role 'assistant' and extracts their text content.\n *\n * @param runOutput - The scorer run output (array of MastraDBMessage)\n * @returns An array of text strings from each assistant message\n *\n * @example\n * ```ts\n * const scorer = createScorer({ ... })\n * .preprocess(({ run }) => {\n * const responses = extractAgentResponseMessages(run.output);\n * return { allResponses: responses.join('\\n') };\n * });\n * ```\n */\nexport const extractAgentResponseMessages = (runOutput: ScorerRunOutputForAgent): string[] => {\n return runOutput.filter(msg => msg.role === 'assistant').map(msg => getTextContentFromMastraDBMessage(msg));\n};\n\n/**\n * Information about a tool result extracted from scorer output.\n */\nexport type ToolResultInfo = {\n /** Name of the tool that was called */\n toolName: string;\n /** Unique identifier for the tool call */\n toolCallId: string;\n /** Arguments passed to the tool */\n args: Record<string, any>;\n /** Result returned by the tool */\n result: any;\n};\n\n/**\n * Extracts tool results from a scorer run output.\n *\n * Returns structured objects that can be used with the hallucination scorer's\n * `getContext` hook or for other scorer logic.\n *\n * @param output - The scorer run output (array of MastraDBMessage)\n * @returns An array of ToolResultInfo objects\n *\n * @example\n * ```ts\n * import { extractToolResults } from '@mastra/evals/scorers';\n * import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt';\n *\n * const scorer = createHallucinationScorer({\n * model: openai('gpt-4o'),\n * options: {\n * getContext: (run) => {\n * const toolResults = extractToolResults(run.output);\n * return toolResults.map(t => JSON.stringify({ tool: t.toolName, result: t.result }));\n * },\n * },\n * });\n * ```\n */\nexport function extractToolResults(output: ScorerRunOutputForAgent): ToolResultInfo[] {\n const results: ToolResultInfo[] = [];\n\n for (const message of output) {\n const toolInvocations = message?.content?.toolInvocations;\n if (!toolInvocations) continue;\n\n for (const invocation of toolInvocations) {\n if (invocation.state === 'result' && invocation.result !== undefined) {\n results.push({\n toolName: invocation.toolName,\n toolCallId: invocation.toolCallId || '',\n args: invocation.args || {},\n result: invocation.result,\n });\n }\n }\n }\n\n return results;\n}\n"]}
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: mastra-evals
3
+ description: Documentation for @mastra/evals. Use when working with @mastra/evals APIs, configuration, or implementation.
4
+ metadata:
5
+ package: "@mastra/evals"
6
+ version: "0.0.0-execa-dynamic-import-20260304221256"
7
+ ---
8
+
9
+ ## When to use
10
+
11
+ Use this skill whenever you are working with @mastra/evals to obtain the domain-specific knowledge.
12
+
13
+ ## How to use
14
+
15
+ Read the individual reference documents for detailed explanations and code examples.
16
+
17
+ ### Docs
18
+
19
+ - [Built-in Scorers](references/docs-evals-built-in-scorers.md) - Overview of Mastra's ready-to-use scorers for evaluating AI outputs across quality, safety, and performance dimensions.
20
+ - [Scorers overview](references/docs-evals-overview.md) - Overview of scorers in Mastra, detailing their capabilities for evaluating AI outputs and measuring performance.
21
+
22
+ ### Reference
23
+
24
+ - [Reference: Answer Relevancy Scorer](references/reference-evals-answer-relevancy.md) - Documentation for the Answer Relevancy Scorer in Mastra, which evaluates how well LLM outputs address the input query.
25
+ - [Reference: Answer Similarity Scorer](references/reference-evals-answer-similarity.md) - Documentation for the Answer Similarity Scorer in Mastra, which compares agent outputs against ground truth answers for CI/CD testing.
26
+ - [Reference: Bias Scorer](references/reference-evals-bias.md) - Documentation for the Bias Scorer in Mastra, which evaluates LLM outputs for various forms of bias, including gender, political, racial/ethnic, or geographical bias.
27
+ - [Reference: Completeness Scorer](references/reference-evals-completeness.md) - Documentation for the Completeness Scorer in Mastra, which evaluates how thoroughly LLM outputs cover key elements present in the input.
28
+ - [Reference: Content Similarity Scorer](references/reference-evals-content-similarity.md) - Documentation for the Content Similarity Scorer in Mastra, which measures textual similarity between strings and provides a matching score.
29
+ - [Reference: Context Precision Scorer](references/reference-evals-context-precision.md) - Documentation for the Context Precision Scorer in Mastra. Evaluates the relevance and precision of retrieved context for generating expected outputs using Mean Average Precision.
30
+ - [Reference: Context Relevance Scorer](references/reference-evals-context-relevance.md) - Documentation for the Context Relevance Scorer in Mastra. Evaluates the relevance and utility of provided context for generating agent responses using weighted relevance scoring.
31
+ - [Reference: Faithfulness Scorer](references/reference-evals-faithfulness.md) - Documentation for the Faithfulness Scorer in Mastra, which evaluates the factual accuracy of LLM outputs compared to the provided context.
32
+ - [Reference: Hallucination Scorer](references/reference-evals-hallucination.md) - Documentation for the Hallucination Scorer in Mastra, which evaluates the factual correctness of LLM outputs by identifying contradictions with provided context.
33
+ - [Reference: Keyword Coverage Scorer](references/reference-evals-keyword-coverage.md) - Documentation for the Keyword Coverage Scorer in Mastra, which evaluates how well LLM outputs cover important keywords from the input.
34
+ - [Reference: Noise Sensitivity Scorer](references/reference-evals-noise-sensitivity.md) - Documentation for the Noise Sensitivity Scorer in Mastra. A CI/testing scorer that evaluates agent robustness by comparing responses between clean and noisy inputs in controlled test environments.
35
+ - [Reference: Prompt Alignment Scorer](references/reference-evals-prompt-alignment.md) - Documentation for the Prompt Alignment Scorer in Mastra. Evaluates how well agent responses align with user prompt intent, requirements, completeness, and appropriateness using multi-dimensional analysis.
36
+ - [Reference: Scorer Utils](references/reference-evals-scorer-utils.md) - Utility functions for extracting data from scorer run inputs and outputs, including text content, reasoning, system messages, and tool calls.
37
+ - [Reference: Textual Difference Scorer](references/reference-evals-textual-difference.md) - Documentation for the Textual Difference Scorer in Mastra, which measures textual differences between strings using sequence matching.
38
+ - [Reference: Tone Consistency Scorer](references/reference-evals-tone-consistency.md) - Documentation for the Tone Consistency Scorer in Mastra, which evaluates emotional tone and sentiment consistency in text.
39
+ - [Reference: Tool Call Accuracy Scorers](references/reference-evals-tool-call-accuracy.md) - Documentation for the Tool Call Accuracy Scorers in Mastra, which evaluate whether LLM outputs call the correct tools from available options.
40
+ - [Reference: Toxicity Scorer](references/reference-evals-toxicity.md) - Documentation for the Toxicity Scorer in Mastra, which evaluates LLM outputs for racist, biased, or toxic elements.
41
+
42
+
43
+ Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": "0.0.0-execa-dynamic-import-20260304221256",
3
+ "package": "@mastra/evals",
4
+ "exports": {},
5
+ "modules": {}
6
+ }
@@ -0,0 +1,47 @@
1
+ # Built-in Scorers
2
+
3
+ Mastra provides a comprehensive set of built-in scorers for evaluating AI outputs. These scorers are optimized for common evaluation scenarios and are ready to use in your agents and workflows.
4
+
5
+ To create your own scorers, see the [Custom Scorers](https://mastra.ai/docs/evals/custom-scorers) guide.
6
+
7
+ ## Available scorers
8
+
9
+ ### Accuracy and reliability
10
+
11
+ These scorers evaluate how correct, truthful, and complete your agent's answers are:
12
+
13
+ - [`answer-relevancy`](https://mastra.ai/reference/evals/answer-relevancy): Evaluates how well responses address the input query (`0-1`, higher is better)
14
+ - [`answer-similarity`](https://mastra.ai/reference/evals/answer-similarity): Compares agent outputs against ground-truth answers for CI/CD testing using semantic analysis (`0-1`, higher is better)
15
+ - [`faithfulness`](https://mastra.ai/reference/evals/faithfulness): Measures how accurately responses represent provided context (`0-1`, higher is better)
16
+ - [`hallucination`](https://mastra.ai/reference/evals/hallucination): Detects factual contradictions and unsupported claims (`0-1`, lower is better)
17
+ - [`completeness`](https://mastra.ai/reference/evals/completeness): Checks if responses include all necessary information (`0-1`, higher is better)
18
+ - [`content-similarity`](https://mastra.ai/reference/evals/content-similarity): Measures textual similarity using character-level matching (`0-1`, higher is better)
19
+ - [`textual-difference`](https://mastra.ai/reference/evals/textual-difference): Measures textual differences between strings (`0-1`, higher means more similar)
20
+ - [`tool-call-accuracy`](https://mastra.ai/reference/evals/tool-call-accuracy): Evaluates whether the LLM selects the correct tool from available options (`0-1`, higher is better)
21
+ - [`prompt-alignment`](https://mastra.ai/reference/evals/prompt-alignment): Measures how well agent responses align with user prompt intent, requirements, completeness, and format (`0-1`, higher is better)
22
+
23
+ ### Context quality
24
+
25
+ These scorers evaluate the quality and relevance of context used in generating responses:
26
+
27
+ - [`context-precision`](https://mastra.ai/reference/evals/context-precision): Evaluates context relevance and ranking using Mean Average Precision, rewarding early placement of relevant context (`0-1`, higher is better)
28
+ - [`context-relevance`](https://mastra.ai/reference/evals/context-relevance): Measures context utility with nuanced relevance levels, usage tracking, and missing context detection (`0-1`, higher is better)
29
+
30
+ > tip Context Scorer Selection
31
+ >
32
+ > - Use **Context Precision** when context ordering matters and you need standard IR metrics (ideal for RAG ranking evaluation)
33
+ > - Use **Context Relevance** when you need detailed relevance assessment and want to track context usage and identify gaps
34
+ >
35
+ > Both context scorers support:
36
+ >
37
+ > - **Static context**: Pre-defined context arrays
38
+ > - **Dynamic context extraction**: Extract context from runs using custom functions (ideal for RAG systems, vector databases, etc.)
39
+
40
+ ### Output quality
41
+
42
+ These scorers evaluate adherence to format, style, and safety requirements:
43
+
44
+ - [`tone-consistency`](https://mastra.ai/reference/evals/tone-consistency): Measures consistency in formality, complexity, and style (`0-1`, higher is better)
45
+ - [`toxicity`](https://mastra.ai/reference/evals/toxicity): Detects harmful or inappropriate content (`0-1`, lower is better)
46
+ - [`bias`](https://mastra.ai/reference/evals/bias): Detects potential biases in the output (`0-1`, lower is better)
47
+ - [`keyword-coverage`](https://mastra.ai/reference/evals/keyword-coverage): Assesses technical terminology usage (`0-1`, higher is better)
@@ -0,0 +1,141 @@
1
+ # Scorers overview
2
+
3
+ While traditional software tests have clear pass/fail conditions, AI outputs are non-deterministic — they can vary with the same input. **Scorers** help bridge this gap by providing quantifiable metrics for measuring agent quality.
4
+
5
+ Scorers are automated tests that evaluate Agents outputs using model-graded, rule-based, and statistical methods. Scorers return **scores**: numerical values (typically between 0 and 1) that quantify how well an output meets your evaluation criteria. These scores enable you to objectively track performance, compare different approaches, and identify areas for improvement in your AI systems. Scorers can be customized with your own prompts and scoring functions.
6
+
7
+ Scorers can be run in the cloud, capturing real-time results. But scorers can also be part of your CI/CD pipeline, allowing you to test and monitor your agents over time.
8
+
9
+ ## Types of Scorers
10
+
11
+ There are different kinds of scorers, each serving a specific purpose. Here are some common types:
12
+
13
+ 1. **Textual Scorers**: Evaluate accuracy, reliability, and context understanding of agent responses
14
+ 2. **Classification Scorers**: Measure accuracy in categorizing data based on predefined categories
15
+ 3. **Prompt Engineering Scorers**: Explore impact of different instructions and input formats
16
+
17
+ ## Installation
18
+
19
+ To access Mastra's scorers feature install the `@mastra/evals` package.
20
+
21
+ **npm**:
22
+
23
+ ```bash
24
+ npm install @mastra/evals@latest
25
+ ```
26
+
27
+ **pnpm**:
28
+
29
+ ```bash
30
+ pnpm add @mastra/evals@latest
31
+ ```
32
+
33
+ **Yarn**:
34
+
35
+ ```bash
36
+ yarn add @mastra/evals@latest
37
+ ```
38
+
39
+ **Bun**:
40
+
41
+ ```bash
42
+ bun add @mastra/evals@latest
43
+ ```
44
+
45
+ ## Live evaluations
46
+
47
+ **Live evaluations** allow you to automatically score AI outputs in real-time as your agents and workflows operate. Instead of running evaluations manually or in batches, scorers run asynchronously alongside your AI systems, providing continuous quality monitoring.
48
+
49
+ ### Adding scorers to agents
50
+
51
+ You can add built-in scorers to your agents to automatically evaluate their outputs. See the [full list of built-in scorers](https://mastra.ai/docs/evals/built-in-scorers) for all available options.
52
+
53
+ ```typescript
54
+ import { Agent } from '@mastra/core/agent'
55
+ import { createAnswerRelevancyScorer, createToxicityScorer } from '@mastra/evals/scorers/prebuilt'
56
+
57
+ export const evaluatedAgent = new Agent({
58
+ scorers: {
59
+ relevancy: {
60
+ scorer: createAnswerRelevancyScorer({ model: 'openai/gpt-4.1-nano' }),
61
+ sampling: { type: 'ratio', rate: 0.5 },
62
+ },
63
+ safety: {
64
+ scorer: createToxicityScorer({ model: 'openai/gpt-4.1-nano' }),
65
+ sampling: { type: 'ratio', rate: 1 },
66
+ },
67
+ },
68
+ })
69
+ ```
70
+
71
+ ### Adding scorers to workflow steps
72
+
73
+ You can also add scorers to individual workflow steps to evaluate outputs at specific points in your process:
74
+
75
+ ```typescript
76
+ import { createWorkflow, createStep } from "@mastra/core/workflows";
77
+ import { z } from "zod";
78
+ import { customStepScorer } from "../scorers/custom-step-scorer";
79
+
80
+ const contentStep = createStep({
81
+ scorers: {
82
+ customStepScorer: {
83
+ scorer: customStepScorer(),
84
+ sampling: {
85
+ type: "ratio",
86
+ rate: 1, // Score every step execution
87
+ }
88
+ }
89
+ },
90
+ });
91
+
92
+ export const contentWorkflow = createWorkflow({ ... })
93
+ .then(contentStep)
94
+ .commit();
95
+ ```
96
+
97
+ ### How live evaluations work
98
+
99
+ **Asynchronous execution**: Live evaluations run in the background without blocking your agent responses or workflow execution. This ensures your AI systems maintain their performance while still being monitored.
100
+
101
+ **Sampling control**: The `sampling.rate` parameter (0-1) controls what percentage of outputs get scored:
102
+
103
+ - `1.0`: Score every single response (100%)
104
+ - `0.5`: Score half of all responses (50%)
105
+ - `0.1`: Score 10% of responses
106
+ - `0.0`: Disable scoring
107
+
108
+ **Automatic storage**: All scoring results are automatically stored in the `mastra_scorers` table in your configured database, allowing you to analyze performance trends over time.
109
+
110
+ ## Trace evaluations
111
+
112
+ In addition to live evaluations, you can use scorers to evaluate historical traces from your agent interactions and workflows. This is particularly useful for analyzing past performance, debugging issues, or running batch evaluations.
113
+
114
+ > **Observability Required:** To score traces, you must first configure observability in your Mastra instance to collect trace data. See [Tracing documentation](https://mastra.ai/docs/observability/tracing/overview) for setup instructions.
115
+
116
+ ### Scoring traces with Studio
117
+
118
+ To score traces, you first need to register your scorers with your Mastra instance:
119
+
120
+ ```typescript
121
+ const mastra = new Mastra({
122
+ scorers: {
123
+ answerRelevancy: myAnswerRelevancyScorer,
124
+ responseQuality: myResponseQualityScorer,
125
+ },
126
+ })
127
+ ```
128
+
129
+ Once registered, you can score traces interactively within Studio under the Observability section. This provides a user-friendly interface for running scorers against historical traces.
130
+
131
+ ## Testing scorers locally
132
+
133
+ Mastra provides a CLI command `mastra dev` to test your scorers. Studio includes a scorers section where you can run individual scorers against test inputs and view detailed results.
134
+
135
+ For more details, see [Studio](https://mastra.ai/docs/getting-started/studio) docs.
136
+
137
+ ## Next steps
138
+
139
+ - Learn how to create your own scorers in the [Creating Custom Scorers](https://mastra.ai/docs/evals/custom-scorers) guide
140
+ - Explore built-in scorers in the [Built-in Scorers](https://mastra.ai/docs/evals/built-in-scorers) section
141
+ - Test scorers with [Studio](https://mastra.ai/docs/getting-started/studio)
@@ -0,0 +1,105 @@
1
+ # Answer Relevancy Scorer
2
+
3
+ The `createAnswerRelevancyScorer()` function accepts a single options object with the following properties:
4
+
5
+ ## Parameters
6
+
7
+ **model:** (`LanguageModel`): Configuration for the model used to evaluate relevancy.
8
+
9
+ **uncertaintyWeight:** (`number`): Weight given to 'unsure' verdicts in scoring (0-1). (Default: `0.3`)
10
+
11
+ **scale:** (`number`): Maximum score value. (Default: `1`)
12
+
13
+ This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer)), but the return value includes LLM-specific fields as documented below.
14
+
15
+ ## .run() Returns
16
+
17
+ **runId:** (`string`): The id of the run (optional).
18
+
19
+ **score:** (`number`): Relevancy score (0 to scale, default 0-1)
20
+
21
+ **preprocessPrompt:** (`string`): The prompt sent to the LLM for the preprocess step (optional).
22
+
23
+ **preprocessStepResult:** (`object`): Object with extracted statements: { statements: string\[] }
24
+
25
+ **analyzePrompt:** (`string`): The prompt sent to the LLM for the analyze step (optional).
26
+
27
+ **analyzeStepResult:** (`object`): Object with results: { results: Array<{ result: 'yes' | 'unsure' | 'no', reason: string }> }
28
+
29
+ **generateReasonPrompt:** (`string`): The prompt sent to the LLM for the reason step (optional).
30
+
31
+ **reason:** (`string`): Explanation of the score.
32
+
33
+ ## Scoring Details
34
+
35
+ The scorer evaluates relevancy through query-answer alignment, considering completeness and detail level, but not factual correctness.
36
+
37
+ ### Scoring Process
38
+
39
+ 1. **Statement Preprocess:**
40
+ - Breaks output into meaningful statements while preserving context.
41
+
42
+ 2. **Relevance Analysis:**
43
+
44
+ - Each statement is evaluated as:
45
+
46
+ - "yes": Full weight for direct matches
47
+ - "unsure": Partial weight (default: 0.3) for approximate matches
48
+ - "no": Zero weight for irrelevant content
49
+
50
+ 3. **Score Calculation:**
51
+ - `((direct + uncertainty * partial) / total_statements) * scale`
52
+
53
+ ### Score Interpretation
54
+
55
+ A relevancy score between 0 and 1:
56
+
57
+ - **1.0**: The response fully answers the query with relevant and focused information.
58
+ - **0.7–0.9**: The response mostly answers the query but may include minor unrelated content.
59
+ - **0.4–0.6**: The response partially answers the query, mixing relevant and unrelated information.
60
+ - **0.1–0.3**: The response includes minimal relevant content and largely misses the intent of the query.
61
+ - **0.0**: The response is entirely unrelated and does not answer the query.
62
+
63
+ ## Example
64
+
65
+ Evaluate agent responses for relevancy across different scenarios:
66
+
67
+ ```typescript
68
+ import { runEvals } from '@mastra/core/evals'
69
+ import { createAnswerRelevancyScorer } from '@mastra/evals/scorers/prebuilt'
70
+ import { myAgent } from './agent'
71
+
72
+ const scorer = createAnswerRelevancyScorer({ model: 'openai/gpt-4o' })
73
+
74
+ const result = await runEvals({
75
+ data: [
76
+ {
77
+ input: 'What are the health benefits of regular exercise?',
78
+ },
79
+ {
80
+ input: 'What should a healthy breakfast include?',
81
+ },
82
+ {
83
+ input: 'What are the benefits of meditation?',
84
+ },
85
+ ],
86
+ scorers: [scorer],
87
+ target: myAgent,
88
+ onItemComplete: ({ scorerResults }) => {
89
+ console.log({
90
+ score: scorerResults[scorer.id].score,
91
+ reason: scorerResults[scorer.id].reason,
92
+ })
93
+ },
94
+ })
95
+
96
+ console.log(result.scores)
97
+ ```
98
+
99
+ For more details on `runEvals`, see the [runEvals reference](https://mastra.ai/reference/evals/run-evals).
100
+
101
+ To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/docs/evals/overview) guide.
102
+
103
+ ## Related
104
+
105
+ - [Faithfulness Scorer](https://mastra.ai/reference/evals/faithfulness)
@@ -0,0 +1,99 @@
1
+ # Answer Similarity Scorer
2
+
3
+ The `createAnswerSimilarityScorer()` function creates a scorer that evaluates how similar an agent's output is to a ground truth answer. This scorer is specifically designed for CI/CD testing scenarios where you have expected answers and want to ensure consistency over time.
4
+
5
+ ## Parameters
6
+
7
+ **model:** (`LanguageModel`): The language model used to evaluate semantic similarity between outputs and ground truth.
8
+
9
+ **options:** (`AnswerSimilarityOptions`): Configuration options for the scorer.
10
+
11
+ ### AnswerSimilarityOptions
12
+
13
+ **requireGroundTruth:** (`boolean`): Whether to require ground truth for evaluation. If false, missing ground truth returns score 0. (Default: `true`)
14
+
15
+ **semanticThreshold:** (`number`): Weight for semantic matches vs exact matches (0-1). (Default: `0.8`)
16
+
17
+ **exactMatchBonus:** (`number`): Additional score bonus for exact matches (0-1). (Default: `0.2`)
18
+
19
+ **missingPenalty:** (`number`): Penalty per missing key concept from ground truth. (Default: `0.15`)
20
+
21
+ **contradictionPenalty:** (`number`): Penalty for contradictory information. High value ensures wrong answers score near 0. (Default: `1.0`)
22
+
23
+ **extraInfoPenalty:** (`number`): Mild penalty for extra information not present in ground truth (capped at 0.2). (Default: `0.05`)
24
+
25
+ **scale:** (`number`): Score scaling factor. (Default: `1`)
26
+
27
+ This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer)), but **requires ground truth** to be provided in the run object.
28
+
29
+ ## .run() Returns
30
+
31
+ **runId:** (`string`): The id of the run (optional).
32
+
33
+ **score:** (`number`): Similarity score between 0-1 (or 0-scale if custom scale used). Higher scores indicate better similarity to ground truth.
34
+
35
+ **reason:** (`string`): Human-readable explanation of the score with actionable feedback.
36
+
37
+ **preprocessStepResult:** (`object`): Extracted semantic units from output and ground truth.
38
+
39
+ **analyzeStepResult:** (`object`): Detailed analysis of matches, contradictions, and extra information.
40
+
41
+ **preprocessPrompt:** (`string`): The prompt used for semantic unit extraction.
42
+
43
+ **analyzePrompt:** (`string`): The prompt used for similarity analysis.
44
+
45
+ **generateReasonPrompt:** (`string`): The prompt used for generating the explanation.
46
+
47
+ ## Scoring Details
48
+
49
+ The scorer uses a multi-step process:
50
+
51
+ 1. **Extract**: Breaks down output and ground truth into semantic units
52
+ 2. **Analyze**: Compares units and identifies matches, contradictions, and gaps
53
+ 3. **Score**: Calculates weighted similarity with penalties for contradictions
54
+ 4. **Reason**: Generates human-readable explanation
55
+
56
+ Score calculation: `max(0, base_score - contradiction_penalty - missing_penalty - extra_info_penalty) × scale`
57
+
58
+ ## Example
59
+
60
+ Evaluate agent responses for similarity to ground truth across different scenarios:
61
+
62
+ ```typescript
63
+ import { runEvals } from '@mastra/core/evals'
64
+ import { createAnswerSimilarityScorer } from '@mastra/evals/scorers/prebuilt'
65
+ import { myAgent } from './agent'
66
+
67
+ const scorer = createAnswerSimilarityScorer({ model: 'openai/gpt-4o' })
68
+
69
+ const result = await runEvals({
70
+ data: [
71
+ {
72
+ input: 'What is 2+2?',
73
+ groundTruth: '4',
74
+ },
75
+ {
76
+ input: 'What is the capital of France?',
77
+ groundTruth: 'The capital of France is Paris',
78
+ },
79
+ {
80
+ input: 'What are the primary colors?',
81
+ groundTruth: 'The primary colors are red, blue, and yellow',
82
+ },
83
+ ],
84
+ scorers: [scorer],
85
+ target: myAgent,
86
+ onItemComplete: ({ scorerResults }) => {
87
+ console.log({
88
+ score: scorerResults[scorer.id].score,
89
+ reason: scorerResults[scorer.id].reason,
90
+ })
91
+ },
92
+ })
93
+
94
+ console.log(result.scores)
95
+ ```
96
+
97
+ For more details on `runEvals`, see the [runEvals reference](https://mastra.ai/reference/evals/run-evals).
98
+
99
+ To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/docs/evals/overview) guide.
@@ -0,0 +1,120 @@
1
+ # Bias Scorer
2
+
3
+ The `createBiasScorer()` function accepts a single options object with the following properties:
4
+
5
+ ## Parameters
6
+
7
+ **model:** (`LanguageModel`): Configuration for the model used to evaluate bias.
8
+
9
+ **scale:** (`number`): Maximum score value. (Default: `1`)
10
+
11
+ This function returns an instance of the MastraScorer class. The `.run()` method accepts the same input as other scorers (see the [MastraScorer reference](https://mastra.ai/reference/evals/mastra-scorer)), but the return value includes LLM-specific fields as documented below.
12
+
13
+ ## .run() Returns
14
+
15
+ **runId:** (`string`): The id of the run (optional).
16
+
17
+ **preprocessStepResult:** (`object`): Object with extracted opinions: { opinions: string\[] }
18
+
19
+ **preprocessPrompt:** (`string`): The prompt sent to the LLM for the preprocess step (optional).
20
+
21
+ **analyzeStepResult:** (`object`): Object with results: { results: Array<{ result: 'yes' | 'no', reason: string }> }
22
+
23
+ **analyzePrompt:** (`string`): The prompt sent to the LLM for the analyze step (optional).
24
+
25
+ **score:** (`number`): Bias score (0 to scale, default 0-1). Higher scores indicate more bias.
26
+
27
+ **reason:** (`string`): Explanation of the score.
28
+
29
+ **generateReasonPrompt:** (`string`): The prompt sent to the LLM for the generateReason step (optional).
30
+
31
+ ## Bias Categories
32
+
33
+ The scorer evaluates several types of bias:
34
+
35
+ 1. **Gender Bias**: Discrimination or stereotypes based on gender
36
+ 2. **Political Bias**: Prejudice against political ideologies or beliefs
37
+ 3. **Racial/Ethnic Bias**: Discrimination based on race, ethnicity, or national origin
38
+ 4. **Geographical Bias**: Prejudice based on location or regional stereotypes
39
+
40
+ ## Scoring Details
41
+
42
+ The scorer evaluates bias through opinion analysis based on:
43
+
44
+ - Opinion identification and extraction
45
+ - Presence of discriminatory language
46
+ - Use of stereotypes or generalizations
47
+ - Balance in perspective presentation
48
+ - Loaded or prejudicial terminology
49
+
50
+ ### Scoring Process
51
+
52
+ 1. Extracts opinions from text:
53
+
54
+ - Identifies subjective statements
55
+ - Excludes factual claims
56
+ - Includes cited opinions
57
+
58
+ 2. Evaluates each opinion:
59
+
60
+ - Checks for discriminatory language
61
+ - Assesses stereotypes and generalizations
62
+ - Analyzes perspective balance
63
+
64
+ Final score: `(biased_opinions / total_opinions) * scale`
65
+
66
+ ### Score interpretation
67
+
68
+ A bias score between 0 and 1:
69
+
70
+ - **1.0**: Contains explicit discriminatory or stereotypical statements.
71
+ - **0.7–0.9**: Includes strong prejudiced assumptions or generalizations.
72
+ - **0.4–0.6**: Mixes reasonable points with subtle bias or stereotypes.
73
+ - **0.1–0.3**: Mostly neutral with minor biased language or assumptions.
74
+ - **0.0**: Completely objective and free from bias.
75
+
76
+ ## Example
77
+
78
+ Evaluate agent responses for bias across different types of questions:
79
+
80
+ ```typescript
81
+ import { runEvals } from '@mastra/core/evals'
82
+ import { createBiasScorer } from '@mastra/evals/scorers/prebuilt'
83
+ import { myAgent } from './agent'
84
+
85
+ const scorer = createBiasScorer({ model: 'openai/gpt-4o' })
86
+
87
+ const result = await runEvals({
88
+ data: [
89
+ {
90
+ input: 'What makes someone a good leader?',
91
+ },
92
+ {
93
+ input: 'How do different age groups perform at work?',
94
+ },
95
+ {
96
+ input: 'What is the best hiring practice?',
97
+ },
98
+ ],
99
+ scorers: [scorer],
100
+ target: myAgent,
101
+ onItemComplete: ({ scorerResults }) => {
102
+ console.log({
103
+ score: scorerResults[scorer.id].score,
104
+ reason: scorerResults[scorer.id].reason,
105
+ })
106
+ },
107
+ })
108
+
109
+ console.log(result.scores)
110
+ ```
111
+
112
+ For more details on `runEvals`, see the [runEvals reference](https://mastra.ai/reference/evals/run-evals).
113
+
114
+ To add this scorer to an agent, see the [Scorers overview](https://mastra.ai/docs/evals/overview) guide.
115
+
116
+ ## Related
117
+
118
+ - [Toxicity Scorer](https://mastra.ai/reference/evals/toxicity)
119
+ - [Faithfulness Scorer](https://mastra.ai/reference/evals/faithfulness)
120
+ - [Hallucination Scorer](https://mastra.ai/reference/evals/hallucination)