@mastra/evals 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807173433

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 (253) hide show
  1. package/CHANGELOG.md +950 -5
  2. package/LICENSE.md +15 -0
  3. package/README.md +19 -159
  4. package/dist/checks-64AonnEK.js +379 -0
  5. package/dist/checks-64AonnEK.js.map +1 -0
  6. package/dist/checks-DGTgg-nW.cjs +479 -0
  7. package/dist/checks-DGTgg-nW.cjs.map +1 -0
  8. package/dist/checks.cjs +14 -0
  9. package/dist/checks.d.ts +3 -0
  10. package/dist/checks.d.ts.map +1 -0
  11. package/dist/checks.js +2 -0
  12. package/dist/docs/SKILL.md +49 -0
  13. package/dist/docs/assets/SOURCE_MAP.json +6 -0
  14. package/dist/docs/references/docs-evals-built-in-scorers.md +66 -0
  15. package/dist/docs/references/docs-evals-overview.md +163 -0
  16. package/dist/docs/references/docs-evals-quick-checks.md +137 -0
  17. package/dist/docs/references/reference-evals-answer-relevancy.md +107 -0
  18. package/dist/docs/references/reference-evals-answer-similarity.md +99 -0
  19. package/dist/docs/references/reference-evals-bias.md +122 -0
  20. package/dist/docs/references/reference-evals-checks.md +212 -0
  21. package/dist/docs/references/reference-evals-completeness.md +138 -0
  22. package/dist/docs/references/reference-evals-content-similarity.md +103 -0
  23. package/dist/docs/references/reference-evals-context-precision.md +198 -0
  24. package/dist/docs/references/reference-evals-context-recall.md +205 -0
  25. package/dist/docs/references/reference-evals-context-relevance.md +533 -0
  26. package/dist/docs/references/reference-evals-faithfulness.md +116 -0
  27. package/dist/docs/references/reference-evals-hallucination.md +206 -0
  28. package/dist/docs/references/reference-evals-keyword-coverage.md +130 -0
  29. package/dist/docs/references/reference-evals-noise-sensitivity.md +677 -0
  30. package/dist/docs/references/reference-evals-prompt-alignment.md +617 -0
  31. package/dist/docs/references/reference-evals-rubric.md +115 -0
  32. package/dist/docs/references/reference-evals-scorer-utils.md +516 -0
  33. package/dist/docs/references/reference-evals-summarization.md +203 -0
  34. package/dist/docs/references/reference-evals-textual-difference.md +115 -0
  35. package/dist/docs/references/reference-evals-tone-consistency.md +121 -0
  36. package/dist/docs/references/reference-evals-tool-call-accuracy.md +535 -0
  37. package/dist/docs/references/reference-evals-toxicity.md +125 -0
  38. package/dist/docs/references/reference-evals-trajectory-accuracy.md +629 -0
  39. package/dist/index.cjs +12 -91
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.ts +11 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +13 -87
  44. package/dist/index.js.map +1 -1
  45. package/dist/scorers/code/checks/index.d.ts +214 -0
  46. package/dist/scorers/code/checks/index.d.ts.map +1 -0
  47. package/dist/scorers/code/completeness/index.d.ts +1 -1
  48. package/dist/scorers/code/completeness/index.d.ts.map +1 -1
  49. package/dist/scorers/code/content-similarity/index.d.ts +1 -1
  50. package/dist/scorers/code/content-similarity/index.d.ts.map +1 -1
  51. package/dist/scorers/code/index.d.ts +2 -0
  52. package/dist/scorers/code/index.d.ts.map +1 -1
  53. package/dist/scorers/code/keyword-coverage/index.d.ts +1 -1
  54. package/dist/scorers/code/keyword-coverage/index.d.ts.map +1 -1
  55. package/dist/scorers/code/textual-difference/index.d.ts +1 -1
  56. package/dist/scorers/code/textual-difference/index.d.ts.map +1 -1
  57. package/dist/scorers/code/tone/index.d.ts +1 -1
  58. package/dist/scorers/code/tone/index.d.ts.map +1 -1
  59. package/dist/scorers/code/tool-call-accuracy/index.d.ts +2 -2
  60. package/dist/scorers/code/tool-call-accuracy/index.d.ts.map +1 -1
  61. package/dist/scorers/code/trajectory/index.d.ts +164 -0
  62. package/dist/scorers/code/trajectory/index.d.ts.map +1 -0
  63. package/dist/scorers/index.d.ts +1 -0
  64. package/dist/scorers/index.d.ts.map +1 -1
  65. package/dist/scorers/llm/answer-relevancy/index.d.ts +2 -1
  66. package/dist/scorers/llm/answer-relevancy/index.d.ts.map +1 -1
  67. package/dist/scorers/llm/answer-similarity/index.d.ts +3 -2
  68. package/dist/scorers/llm/answer-similarity/index.d.ts.map +1 -1
  69. package/dist/scorers/llm/bias/index.d.ts +2 -2
  70. package/dist/scorers/llm/bias/index.d.ts.map +1 -1
  71. package/dist/scorers/llm/context-precision/index.d.ts +4 -3
  72. package/dist/scorers/llm/context-precision/index.d.ts.map +1 -1
  73. package/dist/scorers/llm/context-recall/index.d.ts +20 -0
  74. package/dist/scorers/llm/context-recall/index.d.ts.map +1 -0
  75. package/dist/scorers/llm/context-recall/prompts.d.ts +19 -0
  76. package/dist/scorers/llm/context-recall/prompts.d.ts.map +1 -0
  77. package/dist/scorers/llm/context-relevance/index.d.ts +5 -4
  78. package/dist/scorers/llm/context-relevance/index.d.ts.map +1 -1
  79. package/dist/scorers/llm/faithfulness/index.d.ts +4 -1
  80. package/dist/scorers/llm/faithfulness/index.d.ts.map +1 -1
  81. package/dist/scorers/llm/hallucination/index.d.ts +20 -3
  82. package/dist/scorers/llm/hallucination/index.d.ts.map +1 -1
  83. package/dist/scorers/llm/index.d.ts +4 -0
  84. package/dist/scorers/llm/index.d.ts.map +1 -1
  85. package/dist/scorers/llm/noise-sensitivity/index.d.ts +3 -2
  86. package/dist/scorers/llm/noise-sensitivity/index.d.ts.map +1 -1
  87. package/dist/scorers/llm/prompt-alignment/index.d.ts +7 -7
  88. package/dist/scorers/llm/prompt-alignment/index.d.ts.map +1 -1
  89. package/dist/scorers/llm/rubric/index.d.ts +71 -0
  90. package/dist/scorers/llm/rubric/index.d.ts.map +1 -0
  91. package/dist/scorers/llm/rubric/prompts.d.ts +37 -0
  92. package/dist/scorers/llm/rubric/prompts.d.ts.map +1 -0
  93. package/dist/scorers/llm/summarization/index.d.ts +55 -0
  94. package/dist/scorers/llm/summarization/index.d.ts.map +1 -0
  95. package/dist/scorers/llm/summarization/prompts.d.ts +48 -0
  96. package/dist/scorers/llm/summarization/prompts.d.ts.map +1 -0
  97. package/dist/scorers/llm/tool-call-accuracy/index.d.ts +4 -4
  98. package/dist/scorers/llm/tool-call-accuracy/index.d.ts.map +1 -1
  99. package/dist/scorers/llm/toxicity/index.d.ts +2 -1
  100. package/dist/scorers/llm/toxicity/index.d.ts.map +1 -1
  101. package/dist/scorers/llm/trajectory/index.d.ts +58 -0
  102. package/dist/scorers/llm/trajectory/index.d.ts.map +1 -0
  103. package/dist/scorers/llm/trajectory/prompts.d.ts +20 -0
  104. package/dist/scorers/llm/trajectory/prompts.d.ts.map +1 -0
  105. package/dist/scorers/prebuilt/index.cjs +4546 -0
  106. package/dist/scorers/prebuilt/index.cjs.map +1 -0
  107. package/dist/scorers/prebuilt/index.d.ts +3 -0
  108. package/dist/scorers/prebuilt/index.d.ts.map +1 -0
  109. package/dist/scorers/prebuilt/index.js +4503 -0
  110. package/dist/scorers/prebuilt/index.js.map +1 -0
  111. package/dist/scorers/utils.cjs +967 -58
  112. package/dist/scorers/utils.cjs.map +1 -1
  113. package/dist/scorers/utils.d.ts +563 -16
  114. package/dist/scorers/utils.d.ts.map +1 -1
  115. package/dist/scorers/utils.js +939 -2
  116. package/dist/scorers/utils.js.map +1 -1
  117. package/package.json +42 -68
  118. package/dist/attachListeners.d.ts +0 -4
  119. package/dist/attachListeners.d.ts.map +0 -1
  120. package/dist/chunk-7QAUEU4L.cjs +0 -10
  121. package/dist/chunk-7QAUEU4L.cjs.map +0 -1
  122. package/dist/chunk-EMMSS5I5.cjs +0 -37
  123. package/dist/chunk-EMMSS5I5.cjs.map +0 -1
  124. package/dist/chunk-G3PMV62Z.js +0 -33
  125. package/dist/chunk-G3PMV62Z.js.map +0 -1
  126. package/dist/chunk-IUSAD2BW.cjs +0 -19
  127. package/dist/chunk-IUSAD2BW.cjs.map +0 -1
  128. package/dist/chunk-KHEXN75Q.js +0 -134
  129. package/dist/chunk-KHEXN75Q.js.map +0 -1
  130. package/dist/chunk-QKR2PMLZ.cjs +0 -148
  131. package/dist/chunk-QKR2PMLZ.cjs.map +0 -1
  132. package/dist/chunk-QTWX6TKR.js +0 -8
  133. package/dist/chunk-QTWX6TKR.js.map +0 -1
  134. package/dist/chunk-YGTIO3J5.js +0 -17
  135. package/dist/chunk-YGTIO3J5.js.map +0 -1
  136. package/dist/dist-E463LOAZ.js +0 -16729
  137. package/dist/dist-E463LOAZ.js.map +0 -1
  138. package/dist/dist-KKO3PIUK.cjs +0 -16751
  139. package/dist/dist-KKO3PIUK.cjs.map +0 -1
  140. package/dist/evaluation.d.ts +0 -8
  141. package/dist/evaluation.d.ts.map +0 -1
  142. package/dist/magic-string.es-7ORA5OGR.js +0 -1305
  143. package/dist/magic-string.es-7ORA5OGR.js.map +0 -1
  144. package/dist/magic-string.es-NZ2XWFKN.cjs +0 -1311
  145. package/dist/magic-string.es-NZ2XWFKN.cjs.map +0 -1
  146. package/dist/metrics/index.d.ts +0 -4
  147. package/dist/metrics/index.d.ts.map +0 -1
  148. package/dist/metrics/judge/index.cjs +0 -12
  149. package/dist/metrics/judge/index.cjs.map +0 -1
  150. package/dist/metrics/judge/index.d.ts +0 -7
  151. package/dist/metrics/judge/index.d.ts.map +0 -1
  152. package/dist/metrics/judge/index.js +0 -3
  153. package/dist/metrics/judge/index.js.map +0 -1
  154. package/dist/metrics/llm/answer-relevancy/index.d.ts +0 -16
  155. package/dist/metrics/llm/answer-relevancy/index.d.ts.map +0 -1
  156. package/dist/metrics/llm/answer-relevancy/metricJudge.d.ts +0 -20
  157. package/dist/metrics/llm/answer-relevancy/metricJudge.d.ts.map +0 -1
  158. package/dist/metrics/llm/answer-relevancy/prompts.d.ts +0 -19
  159. package/dist/metrics/llm/answer-relevancy/prompts.d.ts.map +0 -1
  160. package/dist/metrics/llm/bias/index.d.ts +0 -14
  161. package/dist/metrics/llm/bias/index.d.ts.map +0 -1
  162. package/dist/metrics/llm/bias/metricJudge.d.ts +0 -14
  163. package/dist/metrics/llm/bias/metricJudge.d.ts.map +0 -1
  164. package/dist/metrics/llm/bias/prompts.d.ts +0 -14
  165. package/dist/metrics/llm/bias/prompts.d.ts.map +0 -1
  166. package/dist/metrics/llm/context-position/index.d.ts +0 -16
  167. package/dist/metrics/llm/context-position/index.d.ts.map +0 -1
  168. package/dist/metrics/llm/context-position/metricJudge.d.ts +0 -20
  169. package/dist/metrics/llm/context-position/metricJudge.d.ts.map +0 -1
  170. package/dist/metrics/llm/context-position/prompts.d.ts +0 -17
  171. package/dist/metrics/llm/context-position/prompts.d.ts.map +0 -1
  172. package/dist/metrics/llm/context-precision/index.d.ts +0 -16
  173. package/dist/metrics/llm/context-precision/index.d.ts.map +0 -1
  174. package/dist/metrics/llm/context-precision/metricJudge.d.ts +0 -20
  175. package/dist/metrics/llm/context-precision/metricJudge.d.ts.map +0 -1
  176. package/dist/metrics/llm/context-precision/prompts.d.ts +0 -17
  177. package/dist/metrics/llm/context-precision/prompts.d.ts.map +0 -1
  178. package/dist/metrics/llm/context-relevancy/index.d.ts +0 -16
  179. package/dist/metrics/llm/context-relevancy/index.d.ts.map +0 -1
  180. package/dist/metrics/llm/context-relevancy/metricJudge.d.ts +0 -16
  181. package/dist/metrics/llm/context-relevancy/metricJudge.d.ts.map +0 -1
  182. package/dist/metrics/llm/context-relevancy/prompts.d.ts +0 -13
  183. package/dist/metrics/llm/context-relevancy/prompts.d.ts.map +0 -1
  184. package/dist/metrics/llm/contextual-recall/index.d.ts +0 -16
  185. package/dist/metrics/llm/contextual-recall/index.d.ts.map +0 -1
  186. package/dist/metrics/llm/contextual-recall/metricJudge.d.ts +0 -16
  187. package/dist/metrics/llm/contextual-recall/metricJudge.d.ts.map +0 -1
  188. package/dist/metrics/llm/contextual-recall/prompts.d.ts +0 -13
  189. package/dist/metrics/llm/contextual-recall/prompts.d.ts.map +0 -1
  190. package/dist/metrics/llm/faithfulness/index.d.ts +0 -16
  191. package/dist/metrics/llm/faithfulness/index.d.ts.map +0 -1
  192. package/dist/metrics/llm/faithfulness/metricJudge.d.ts +0 -22
  193. package/dist/metrics/llm/faithfulness/metricJudge.d.ts.map +0 -1
  194. package/dist/metrics/llm/faithfulness/prompts.d.ts +0 -20
  195. package/dist/metrics/llm/faithfulness/prompts.d.ts.map +0 -1
  196. package/dist/metrics/llm/hallucination/index.d.ts +0 -16
  197. package/dist/metrics/llm/hallucination/index.d.ts.map +0 -1
  198. package/dist/metrics/llm/hallucination/metricJudge.d.ts +0 -22
  199. package/dist/metrics/llm/hallucination/metricJudge.d.ts.map +0 -1
  200. package/dist/metrics/llm/hallucination/prompts.d.ts +0 -17
  201. package/dist/metrics/llm/hallucination/prompts.d.ts.map +0 -1
  202. package/dist/metrics/llm/index.cjs +0 -2481
  203. package/dist/metrics/llm/index.cjs.map +0 -1
  204. package/dist/metrics/llm/index.d.ts +0 -12
  205. package/dist/metrics/llm/index.d.ts.map +0 -1
  206. package/dist/metrics/llm/index.js +0 -2469
  207. package/dist/metrics/llm/index.js.map +0 -1
  208. package/dist/metrics/llm/prompt-alignment/index.d.ts +0 -33
  209. package/dist/metrics/llm/prompt-alignment/index.d.ts.map +0 -1
  210. package/dist/metrics/llm/prompt-alignment/metricJudge.d.ts +0 -20
  211. package/dist/metrics/llm/prompt-alignment/metricJudge.d.ts.map +0 -1
  212. package/dist/metrics/llm/prompt-alignment/prompts.d.ts +0 -17
  213. package/dist/metrics/llm/prompt-alignment/prompts.d.ts.map +0 -1
  214. package/dist/metrics/llm/summarization/index.d.ts +0 -19
  215. package/dist/metrics/llm/summarization/index.d.ts.map +0 -1
  216. package/dist/metrics/llm/summarization/metricJudge.d.ts +0 -34
  217. package/dist/metrics/llm/summarization/metricJudge.d.ts.map +0 -1
  218. package/dist/metrics/llm/summarization/prompts.d.ts +0 -30
  219. package/dist/metrics/llm/summarization/prompts.d.ts.map +0 -1
  220. package/dist/metrics/llm/toxicity/index.d.ts +0 -14
  221. package/dist/metrics/llm/toxicity/index.d.ts.map +0 -1
  222. package/dist/metrics/llm/toxicity/metricJudge.d.ts +0 -14
  223. package/dist/metrics/llm/toxicity/metricJudge.d.ts.map +0 -1
  224. package/dist/metrics/llm/toxicity/prompts.d.ts +0 -10
  225. package/dist/metrics/llm/toxicity/prompts.d.ts.map +0 -1
  226. package/dist/metrics/llm/types.d.ts +0 -7
  227. package/dist/metrics/llm/types.d.ts.map +0 -1
  228. package/dist/metrics/llm/utils.d.ts +0 -14
  229. package/dist/metrics/llm/utils.d.ts.map +0 -1
  230. package/dist/metrics/nlp/completeness/index.d.ts +0 -21
  231. package/dist/metrics/nlp/completeness/index.d.ts.map +0 -1
  232. package/dist/metrics/nlp/content-similarity/index.d.ts +0 -18
  233. package/dist/metrics/nlp/content-similarity/index.d.ts.map +0 -1
  234. package/dist/metrics/nlp/index.cjs +0 -203
  235. package/dist/metrics/nlp/index.cjs.map +0 -1
  236. package/dist/metrics/nlp/index.d.ts +0 -6
  237. package/dist/metrics/nlp/index.d.ts.map +0 -1
  238. package/dist/metrics/nlp/index.js +0 -190
  239. package/dist/metrics/nlp/index.js.map +0 -1
  240. package/dist/metrics/nlp/keyword-coverage/index.d.ts +0 -13
  241. package/dist/metrics/nlp/keyword-coverage/index.d.ts.map +0 -1
  242. package/dist/metrics/nlp/textual-difference/index.d.ts +0 -15
  243. package/dist/metrics/nlp/textual-difference/index.d.ts.map +0 -1
  244. package/dist/metrics/nlp/tone/index.d.ts +0 -18
  245. package/dist/metrics/nlp/tone/index.d.ts.map +0 -1
  246. package/dist/scorers/code/index.cjs +0 -329
  247. package/dist/scorers/code/index.cjs.map +0 -1
  248. package/dist/scorers/code/index.js +0 -315
  249. package/dist/scorers/code/index.js.map +0 -1
  250. package/dist/scorers/llm/index.cjs +0 -2588
  251. package/dist/scorers/llm/index.cjs.map +0 -1
  252. package/dist/scorers/llm/index.js +0 -2572
  253. package/dist/scorers/llm/index.js.map +0 -1
package/LICENSE.md CHANGED
@@ -1,3 +1,18 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
1
16
  # Apache License 2.0
2
17
 
3
18
  Copyright (c) 2025 Kepler Software, Inc.
package/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # @mastra/evals
2
2
 
3
- A comprehensive evaluation framework for assessing AI model outputs across multiple dimensions.
3
+ `@mastra/evals` ships a collection of scoring utilities you can run locally or inside your own evaluation pipelines. These scorers come in two flavors:
4
+
5
+ - **LLM scorers** – leverage a judge model (e.g. OpenAI, Anthropic) to rate responses for qualities such as faithfulness or toxicity.
6
+ - **Code/NLP scorers** – deterministic heuristics (keyword coverage, similarity, etc.) that do not require an external model.
7
+
8
+ The scorers do not persist results or integrate with Mastra Storage; you decide where and how to record outcomes.
4
9
 
5
10
  ## Installation
6
11
 
@@ -8,171 +13,26 @@ A comprehensive evaluation framework for assessing AI model outputs across multi
8
13
  npm install @mastra/evals
9
14
  ```
10
15
 
11
- ## Overview
12
-
13
- `@mastra/evals` provides a suite of evaluation metrics for assessing AI model outputs. The package includes both LLM-based and NLP-based metrics, enabling both automated and model-assisted evaluation of AI responses.
14
-
15
- ## Features
16
-
17
- ### LLM-Based Metrics
18
-
19
- 1. **Answer Relevancy**
20
- - Evaluates how well an answer addresses the input question
21
- - Considers uncertainty weighting for more nuanced scoring
22
- - Returns detailed reasoning for scores
23
-
24
- 2. **Bias Detection**
25
- - Identifies potential biases in model outputs
26
- - Analyzes opinions and statements for bias indicators
27
- - Provides explanations for detected biases
28
- - Configurable scoring scale
29
-
30
- 3. **Context Precision & Relevancy**
31
- - Assesses how well responses use provided context
32
- - Evaluates accuracy of context usage
33
- - Measures relevance of context to the response
34
- - Analyzes context positioning in responses
35
-
36
- 4. **Faithfulness**
37
- - Verifies that responses are faithful to provided context
38
- - Detects hallucinations or fabricated information
39
- - Evaluates claims against provided context
40
- - Provides detailed analysis of faithfulness breaches
41
-
42
- 5. **Prompt Alignment**
43
- - Measures how well responses follow given instructions
44
- - Evaluates adherence to multiple instruction criteria
45
- - Provides per-instruction scoring
46
- - Supports custom instruction sets
47
-
48
- 6. **Toxicity**
49
- - Detects toxic or harmful content in responses
50
- - Provides detailed reasoning for toxicity verdicts
51
- - Configurable scoring thresholds
52
- - Considers both input and output context
16
+ ## Quick Start
53
17
 
54
- ### NLP-Based Metrics
18
+ ```ts
19
+ import { createFaithfulnessScorer, createContentSimilarityScorer } from '@mastra/evals/scorers/prebuilt';
55
20
 
56
- 1. **Completeness**
57
- - Analyzes structural completeness of responses
58
- - Identifies missing elements from input requirements
59
- - Provides detailed element coverage analysis
60
- - Tracks input-output element ratios
61
-
62
- 2. **Content Similarity**
63
- - Measures text similarity between inputs and outputs
64
- - Configurable for case and whitespace sensitivity
65
- - Returns normalized similarity scores
66
- - Uses string comparison algorithms for accuracy
67
-
68
- 3. **Keyword Coverage**
69
- - Tracks presence of key terms from input in output
70
- - Provides detailed keyword matching statistics
71
- - Calculates coverage ratios
72
- - Useful for ensuring comprehensive responses
73
-
74
- ## Usage
75
-
76
- ### Basic Example
77
-
78
- ```typescript
79
- import { ContentSimilarityMetric, ToxicityMetric } from '@mastra/evals';
80
-
81
- // Initialize metrics
82
- const similarityMetric = new ContentSimilarityMetric({
83
- ignoreCase: true,
84
- ignoreWhitespace: true,
21
+ const faithfulness = createFaithfulnessScorer({
22
+ model: 'openai/gpt-4o-mini')
85
23
  });
86
24
 
87
- const toxicityMetric = new ToxicityMetric({
88
- model: openai('gpt-4'),
89
- scale: 1, // Optional: adjust scoring scale
90
- });
91
-
92
- // Evaluate outputs
93
- const input = 'What is the capital of France?';
94
- const output = 'Paris is the capital of France.';
95
-
96
- const similarityResult = await similarityMetric.measure(input, output);
97
- const toxicityResult = await toxicityMetric.measure(input, output);
98
-
99
- console.log('Similarity Score:', similarityResult.score);
100
- console.log('Toxicity Score:', toxicityResult.score);
101
- ```
25
+ const similarity = createContentSimilarityScorer({ ignoreCase: true });
102
26
 
103
- ### Context-Aware Evaluation
27
+ const answer = 'Paris is the capital of France.';
28
+ const context = ['Paris is the capital of France', 'France is in Europe'];
104
29
 
105
- ```typescript
106
- import { FaithfulnessMetric } from '@mastra/evals';
30
+ const faithfulnessScore = await faithfulness.score({ answer, context });
107
31
 
108
- // Initialize with context
109
- const faithfulnessMetric = new FaithfulnessMetric({
110
- model: openai('gpt-4'),
111
- context: ['Paris is the capital of France', 'Paris has a population of 2.2 million'],
112
- scale: 1,
32
+ const similarityScore = similarity.score({
33
+ input: context[0],
34
+ output: answer
113
35
  });
114
36
 
115
- // Evaluate response against context
116
- const result = await faithfulnessMetric.measure(
117
- 'Tell me about Paris',
118
- 'Paris is the capital of France with 2.2 million residents',
119
- );
120
-
121
- console.log('Faithfulness Score:', result.score);
122
- console.log('Reasoning:', result.reason);
37
+ console.log({ faithfulnessScore, similarityScore });
123
38
  ```
124
-
125
- ## Metric Results
126
-
127
- Each metric returns a standardized result object containing:
128
-
129
- - `score`: Normalized score (typically 0-1)
130
- - `info`: Detailed information about the evaluation
131
- - Additional metric-specific data (e.g., matched keywords, missing elements)
132
-
133
- Some metrics also provide:
134
-
135
- - `reason`: Detailed explanation of the score
136
- - `verdicts`: Individual judgments that contributed to the final score
137
-
138
- ## Telemetry and Logging
139
-
140
- The package includes built-in telemetry and logging capabilities:
141
-
142
- - Automatic evaluation tracking through Mastra Storage
143
- - Integration with OpenTelemetry for performance monitoring
144
- - Detailed evaluation traces for debugging
145
-
146
- ```typescript
147
- import { attachListeners } from '@mastra/evals';
148
-
149
- // Enable basic evaluation tracking
150
- await attachListeners();
151
-
152
- // Store evals in Mastra Storage (if storage is enabled)
153
- await attachListeners(mastra);
154
- // Note: When using in-memory storage, evaluations are isolated to the test process.
155
- // When using file storage, evaluations are persisted and can be queried later.
156
- ```
157
-
158
- ## Environment Variables
159
-
160
- Required for LLM-based metrics:
161
-
162
- - `OPENAI_API_KEY`: For OpenAI model access
163
- - Additional provider keys as needed (Cohere, Anthropic, etc.)
164
-
165
- ## Package Exports
166
-
167
- ```typescript
168
- // Main package exports
169
- import { evaluate } from '@mastra/evals';
170
- // NLP-specific metrics
171
- import { ContentSimilarityMetric } from '@mastra/evals/nlp';
172
- ```
173
-
174
- ## Related Packages
175
-
176
- - `@mastra/core`: Core framework functionality
177
- - `@mastra/engine`: LLM execution engine
178
- - `@mastra/mcp`: Model Context Protocol integration
@@ -0,0 +1,379 @@
1
+ import { extractToolCalls, getTextContentFromMastraDBMessage } from "./scorers/utils.js";
2
+ import { createScorer } from "@mastra/core/evals";
3
+ import stringSimilarity from "string-similarity";
4
+ //#region src/scorers/code/checks/index.ts
5
+ /**
6
+ * Scores 1 if the agent's output text contains the expected substring, 0 otherwise.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { checks } from '@mastra/evals';
11
+ * const scorer = checks.includes('sunny');
12
+ * ```
13
+ */
14
+ function includes(expected, options = {}) {
15
+ const { ignoreCase = true } = options;
16
+ return createScorer({
17
+ id: "check-includes",
18
+ name: "Includes Check",
19
+ description: `Checks if output includes "${expected}"`,
20
+ type: "agent"
21
+ }).preprocess(async ({ run }) => {
22
+ let output = run.output.filter((m) => m.role === "assistant").map((m) => getTextContentFromMastraDBMessage(m)).join(" ");
23
+ let target = expected;
24
+ if (ignoreCase) {
25
+ output = output.toLowerCase();
26
+ target = target.toLowerCase();
27
+ }
28
+ return {
29
+ output,
30
+ target,
31
+ found: output.includes(target)
32
+ };
33
+ }).generateScore(({ results }) => {
34
+ return results.preprocessStepResult?.found ? 1 : 0;
35
+ });
36
+ }
37
+ /**
38
+ * Scores 1 if the agent's output text does NOT contain the substring, 0 otherwise.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { checks } from '@mastra/evals';
43
+ * const scorer = checks.excludes('error');
44
+ * ```
45
+ */
46
+ function excludes(unwanted, options = {}) {
47
+ const { ignoreCase = true } = options;
48
+ return createScorer({
49
+ id: "check-excludes",
50
+ name: "Excludes Check",
51
+ description: `Checks that output does not include "${unwanted}"`,
52
+ type: "agent"
53
+ }).preprocess(async ({ run }) => {
54
+ let output = run.output.filter((m) => m.role === "assistant").map((m) => getTextContentFromMastraDBMessage(m)).join(" ");
55
+ let target = unwanted;
56
+ if (ignoreCase) {
57
+ output = output.toLowerCase();
58
+ target = target.toLowerCase();
59
+ }
60
+ return {
61
+ output,
62
+ target,
63
+ excluded: !output.includes(target)
64
+ };
65
+ }).generateScore(({ results }) => {
66
+ return results.preprocessStepResult?.excluded ? 1 : 0;
67
+ });
68
+ }
69
+ /**
70
+ * Scores 1 if the output text exactly equals the expected string (after optional normalization).
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { checks } from '@mastra/evals';
75
+ * const scorer = checks.equals('Hello, world!');
76
+ * ```
77
+ */
78
+ function equals(expected, options = {}) {
79
+ const { ignoreCase = true } = options;
80
+ return createScorer({
81
+ id: "check-equals",
82
+ name: "Equals Check",
83
+ description: `Checks if output equals "${expected}"`,
84
+ type: "agent"
85
+ }).preprocess(async ({ run }) => {
86
+ let output = run.output.filter((m) => m.role === "assistant").map((m) => getTextContentFromMastraDBMessage(m)).join("");
87
+ let target = expected;
88
+ if (ignoreCase) {
89
+ output = output.toLowerCase();
90
+ target = target.toLowerCase();
91
+ }
92
+ return {
93
+ output,
94
+ target,
95
+ isEqual: output === target
96
+ };
97
+ }).generateScore(({ results }) => {
98
+ return results.preprocessStepResult?.isEqual ? 1 : 0;
99
+ });
100
+ }
101
+ /**
102
+ * Scores 1 if the output matches the given regular expression, 0 otherwise.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import { checks } from '@mastra/evals';
107
+ * const scorer = checks.matches(/\d{1,3}°[FC]/);
108
+ * ```
109
+ */
110
+ function matches(pattern, options = {}) {
111
+ const { exact = false } = options;
112
+ return createScorer({
113
+ id: "check-matches",
114
+ name: "Matches Check",
115
+ description: `Checks if output matches pattern ${pattern}`,
116
+ type: "agent"
117
+ }).preprocess(async ({ run }) => {
118
+ const output = run.output.filter((m) => m.role === "assistant").map((m) => getTextContentFromMastraDBMessage(m)).join("");
119
+ const matched = (exact ? new RegExp(`^${pattern.source}$`, pattern.flags) : pattern).test(output);
120
+ return {
121
+ output,
122
+ pattern: pattern.toString(),
123
+ matched
124
+ };
125
+ }).generateScore(({ results }) => {
126
+ return results.preprocessStepResult?.matched ? 1 : 0;
127
+ });
128
+ }
129
+ /**
130
+ * Returns the string similarity score (0-1) between the output and an expected string.
131
+ * Useful for fuzzy matching when exact equality is too strict.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * import { checks } from '@mastra/evals';
136
+ * const scorer = checks.similarity('Sunny, 72°F');
137
+ * ```
138
+ */
139
+ function similarity(expected, options = {}) {
140
+ const { ignoreCase = true, threshold } = options;
141
+ return createScorer({
142
+ id: "check-similarity",
143
+ name: "Similarity Check",
144
+ description: `Checks string similarity to "${expected}"`,
145
+ type: "agent"
146
+ }).preprocess(async ({ run }) => {
147
+ let output = run.output.filter((m) => m.role === "assistant").map((m) => getTextContentFromMastraDBMessage(m)).join(" ");
148
+ let target = expected;
149
+ if (ignoreCase) {
150
+ output = output.toLowerCase();
151
+ target = target.toLowerCase();
152
+ }
153
+ const score = stringSimilarity.compareTwoStrings(output, target);
154
+ return {
155
+ output,
156
+ target,
157
+ score,
158
+ threshold
159
+ };
160
+ }).generateScore(({ results }) => {
161
+ const score = results.preprocessStepResult?.score ?? 0;
162
+ const t = results.preprocessStepResult?.threshold;
163
+ return t !== void 0 ? score >= t ? 1 : 0 : score;
164
+ });
165
+ }
166
+ /**
167
+ * Scores 1 if the agent called the specified tool (at least `times` times).
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * import { checks } from '@mastra/evals';
172
+ * const scorer = checks.calledTool('get_weather');
173
+ * const twice = checks.calledTool('search', { times: 2 });
174
+ * ```
175
+ */
176
+ function calledTool(toolName, options = {}) {
177
+ const { times = 1 } = options;
178
+ return createScorer({
179
+ id: "check-called-tool",
180
+ name: "Called Tool Check",
181
+ description: `Checks that "${toolName}" was called${times > 1 ? ` at least ${times} times` : ""}`,
182
+ type: "agent"
183
+ }).preprocess(async ({ run }) => {
184
+ const { tools } = extractToolCalls(run.output);
185
+ const count = tools.filter((t) => t === toolName).length;
186
+ return {
187
+ toolName,
188
+ expectedTimes: times,
189
+ actualCount: count,
190
+ passed: count >= times
191
+ };
192
+ }).generateScore(({ results }) => {
193
+ return results.preprocessStepResult?.passed ? 1 : 0;
194
+ });
195
+ }
196
+ /**
197
+ * Scores 1 if the agent did NOT call the specified tool.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * import { checks } from '@mastra/evals';
202
+ * const scorer = checks.didNotCall('delete_user');
203
+ * ```
204
+ */
205
+ function didNotCall(toolName) {
206
+ return createScorer({
207
+ id: "check-did-not-call",
208
+ name: "Did Not Call Check",
209
+ description: `Checks that "${toolName}" was NOT called`,
210
+ type: "agent"
211
+ }).preprocess(async ({ run }) => {
212
+ const { tools } = extractToolCalls(run.output);
213
+ const count = tools.filter((t) => t === toolName).length;
214
+ return {
215
+ toolName,
216
+ count,
217
+ passed: count === 0
218
+ };
219
+ }).generateScore(({ results }) => {
220
+ return results.preprocessStepResult?.passed ? 1 : 0;
221
+ });
222
+ }
223
+ /**
224
+ * Scores 1 if the tools were called in the specified order (relaxed: allows other calls in between).
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * import { checks } from '@mastra/evals';
229
+ * const scorer = checks.toolOrder(['search', 'summarize', 'respond']);
230
+ * ```
231
+ */
232
+ function toolOrder(expectedOrder) {
233
+ return createScorer({
234
+ id: "check-tool-order",
235
+ name: "Tool Order Check",
236
+ description: `Checks tool call order: [${expectedOrder.join(" → ")}]`,
237
+ type: "agent"
238
+ }).preprocess(async ({ run }) => {
239
+ const { tools } = extractToolCalls(run.output);
240
+ let orderIndex = 0;
241
+ for (const tool of tools) if (orderIndex < expectedOrder.length && tool === expectedOrder[orderIndex]) orderIndex++;
242
+ return {
243
+ actualTools: tools,
244
+ expectedOrder,
245
+ passed: orderIndex === expectedOrder.length
246
+ };
247
+ }).generateScore(({ results }) => {
248
+ return results.preprocessStepResult?.passed ? 1 : 0;
249
+ });
250
+ }
251
+ /**
252
+ * Scores 1 if the agent used no more than `max` tool calls.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * import { checks } from '@mastra/evals';
257
+ * const scorer = checks.maxToolCalls(5);
258
+ * ```
259
+ */
260
+ function maxToolCalls(max) {
261
+ return createScorer({
262
+ id: "check-max-tool-calls",
263
+ name: "Max Tool Calls Check",
264
+ description: `Checks that no more than ${max} tool calls were made`,
265
+ type: "agent"
266
+ }).preprocess(async ({ run }) => {
267
+ const { tools } = extractToolCalls(run.output);
268
+ return {
269
+ count: tools.length,
270
+ max,
271
+ passed: tools.length <= max
272
+ };
273
+ }).generateScore(({ results }) => {
274
+ return results.preprocessStepResult?.passed ? 1 : 0;
275
+ });
276
+ }
277
+ /**
278
+ * Scores 1 if the agent made no tool calls at all.
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * import { checks } from '@mastra/evals';
283
+ * const scorer = checks.usedNoTools();
284
+ * ```
285
+ */
286
+ function usedNoTools() {
287
+ return createScorer({
288
+ id: "check-used-no-tools",
289
+ name: "Used No Tools Check",
290
+ description: "Checks that no tools were called",
291
+ type: "agent"
292
+ }).preprocess(async ({ run }) => {
293
+ const { tools } = extractToolCalls(run.output);
294
+ return {
295
+ count: tools.length,
296
+ passed: tools.length === 0
297
+ };
298
+ }).generateScore(({ results }) => {
299
+ return results.preprocessStepResult?.passed ? 1 : 0;
300
+ });
301
+ }
302
+ /**
303
+ * Scores 1 if none of the tool invocations resulted in an error state.
304
+ * Checks for tool invocations with state other than 'result' (i.e., missing results).
305
+ *
306
+ * @example
307
+ * ```ts
308
+ * import { checks } from '@mastra/evals';
309
+ * const scorer = checks.noToolErrors();
310
+ * ```
311
+ */
312
+ function noToolErrors() {
313
+ return createScorer({
314
+ id: "check-no-tool-errors",
315
+ name: "No Tool Errors Check",
316
+ description: "Checks that no tool calls resulted in errors",
317
+ type: "agent"
318
+ }).preprocess(async ({ run }) => {
319
+ const invocations = extractRawInvocations(run.output);
320
+ const errorCount = invocations.filter((inv) => inv.state === "call" || inv.result && inv.result.error).length;
321
+ return {
322
+ errorCount,
323
+ totalCalls: invocations.length,
324
+ passed: errorCount === 0
325
+ };
326
+ }).generateScore(({ results }) => {
327
+ return results.preprocessStepResult?.passed ? 1 : 0;
328
+ });
329
+ }
330
+ function extractRawInvocations(output) {
331
+ const invocations = [];
332
+ for (const message of output) {
333
+ const legacy = message?.content?.toolInvocations;
334
+ const fromParts = legacy ? void 0 : (message?.content)?.parts?.filter((p) => p.type === "tool-invocation").map((p) => p.toolInvocation);
335
+ for (const inv of legacy ?? fromParts ?? []) if (inv) invocations.push(inv);
336
+ }
337
+ return invocations;
338
+ }
339
+ /**
340
+ * Quick Checks — composable micro-scorers for common assertions.
341
+ *
342
+ * These are zero-LLM, zero-ceremony scorers that plug into the existing
343
+ * `scorers: [...]` array anywhere scorers are used. Internally they are
344
+ * standard `createScorer()` instances with the same observability, storage,
345
+ * and pipeline integration as any other scorer.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * import { checks } from '@mastra/evals';
350
+ *
351
+ * await runEvals({
352
+ * data: [...],
353
+ * target: myAgent,
354
+ * scorers: [
355
+ * checks.includes('sunny'),
356
+ * checks.calledTool('get_weather'),
357
+ * checks.toolOrder(['search', 'summarize']),
358
+ * checks.noToolErrors(),
359
+ * ],
360
+ * });
361
+ * ```
362
+ */
363
+ const checks = {
364
+ includes,
365
+ excludes,
366
+ equals,
367
+ matches,
368
+ similarity,
369
+ calledTool,
370
+ didNotCall,
371
+ toolOrder,
372
+ maxToolCalls,
373
+ usedNoTools,
374
+ noToolErrors
375
+ };
376
+ //#endregion
377
+ export { excludes as a, maxToolCalls as c, toolOrder as d, usedNoTools as f, equals as i, noToolErrors as l, checks as n, includes as o, didNotCall as r, matches as s, calledTool as t, similarity as u };
378
+
379
+ //# sourceMappingURL=checks-64AonnEK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checks-64AonnEK.js","names":[],"sources":["../src/scorers/code/checks/index.ts"],"sourcesContent":["import { createScorer } from '@mastra/core/evals';\nimport stringSimilarity from 'string-similarity';\nimport { extractToolCalls, getTextContentFromMastraDBMessage } from '../../utils';\n\n// ─── Output Text Checks ───────────────────────────────────────────────────────\n\nexport interface IncludesOptions {\n /** Case-insensitive match (default: true) */\n ignoreCase?: boolean;\n}\n\n/**\n * Scores 1 if the agent's output text contains the expected substring, 0 otherwise.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.includes('sunny');\n * ```\n */\nexport function includes(expected: string, options: IncludesOptions = {}) {\n const { ignoreCase = true } = options;\n return createScorer({\n id: 'check-includes',\n name: 'Includes Check',\n description: `Checks if output includes \"${expected}\"`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n let output = run.output\n .filter(m => m.role === 'assistant')\n .map(m => getTextContentFromMastraDBMessage(m))\n .join(' ');\n let target = expected;\n if (ignoreCase) {\n output = output.toLowerCase();\n target = target.toLowerCase();\n }\n return { output, target, found: output.includes(target) };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.found ? 1 : 0;\n });\n}\n\n/**\n * Scores 1 if the agent's output text does NOT contain the substring, 0 otherwise.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.excludes('error');\n * ```\n */\nexport function excludes(unwanted: string, options: IncludesOptions = {}) {\n const { ignoreCase = true } = options;\n return createScorer({\n id: 'check-excludes',\n name: 'Excludes Check',\n description: `Checks that output does not include \"${unwanted}\"`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n let output = run.output\n .filter(m => m.role === 'assistant')\n .map(m => getTextContentFromMastraDBMessage(m))\n .join(' ');\n let target = unwanted;\n if (ignoreCase) {\n output = output.toLowerCase();\n target = target.toLowerCase();\n }\n return { output, target, excluded: !output.includes(target) };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.excluded ? 1 : 0;\n });\n}\n\n/**\n * Scores 1 if the output text exactly equals the expected string (after optional normalization).\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.equals('Hello, world!');\n * ```\n */\nexport function equals(expected: string, options: IncludesOptions = {}) {\n const { ignoreCase = true } = options;\n return createScorer({\n id: 'check-equals',\n name: 'Equals Check',\n description: `Checks if output equals \"${expected}\"`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n let output = run.output\n .filter(m => m.role === 'assistant')\n .map(m => getTextContentFromMastraDBMessage(m))\n .join('');\n let target = expected;\n if (ignoreCase) {\n output = output.toLowerCase();\n target = target.toLowerCase();\n }\n return { output, target, isEqual: output === target };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.isEqual ? 1 : 0;\n });\n}\n\nexport interface MatchesOptions {\n /** If true, the output must match the pattern exactly (anchored). Default: false (substring match). */\n exact?: boolean;\n}\n\n/**\n * Scores 1 if the output matches the given regular expression, 0 otherwise.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.matches(/\\d{1,3}°[FC]/);\n * ```\n */\nexport function matches(pattern: RegExp, options: MatchesOptions = {}) {\n const { exact = false } = options;\n return createScorer({\n id: 'check-matches',\n name: 'Matches Check',\n description: `Checks if output matches pattern ${pattern}`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n const output = run.output\n .filter(m => m.role === 'assistant')\n .map(m => getTextContentFromMastraDBMessage(m))\n .join('');\n const regex = exact ? new RegExp(`^${pattern.source}$`, pattern.flags) : pattern;\n const matched = regex.test(output);\n return { output, pattern: pattern.toString(), matched };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.matched ? 1 : 0;\n });\n}\n\nexport interface SimilarityOptions {\n /** Minimum similarity threshold (0-1) to score 1. Default: 0.7 */\n threshold?: number;\n /** Case-insensitive comparison (default: true) */\n ignoreCase?: boolean;\n}\n\n/**\n * Returns the string similarity score (0-1) between the output and an expected string.\n * Useful for fuzzy matching when exact equality is too strict.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.similarity('Sunny, 72°F');\n * ```\n */\nexport function similarity(expected: string, options: SimilarityOptions = {}) {\n const { ignoreCase = true, threshold } = options;\n return createScorer({\n id: 'check-similarity',\n name: 'Similarity Check',\n description: `Checks string similarity to \"${expected}\"`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n let output = run.output\n .filter(m => m.role === 'assistant')\n .map(m => getTextContentFromMastraDBMessage(m))\n .join(' ');\n let target = expected;\n if (ignoreCase) {\n output = output.toLowerCase();\n target = target.toLowerCase();\n }\n const score = stringSimilarity.compareTwoStrings(output, target);\n return { output, target, score, threshold };\n })\n .generateScore(({ results }) => {\n const score = results.preprocessStepResult?.score ?? 0;\n const t = results.preprocessStepResult?.threshold;\n return t !== undefined ? (score >= t ? 1 : 0) : score;\n });\n}\n\n// ─── Tool Call Checks ─────────────────────────────────────────────────────────\n\nexport interface CalledToolOptions {\n /** Minimum number of times the tool must be called. Default: 1 */\n times?: number;\n}\n\n/**\n * Scores 1 if the agent called the specified tool (at least `times` times).\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.calledTool('get_weather');\n * const twice = checks.calledTool('search', { times: 2 });\n * ```\n */\nexport function calledTool(toolName: string, options: CalledToolOptions = {}) {\n const { times = 1 } = options;\n return createScorer({\n id: 'check-called-tool',\n name: 'Called Tool Check',\n description: `Checks that \"${toolName}\" was called${times > 1 ? ` at least ${times} times` : ''}`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n const { tools } = extractToolCalls(run.output);\n const count = tools.filter(t => t === toolName).length;\n return { toolName, expectedTimes: times, actualCount: count, passed: count >= times };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.passed ? 1 : 0;\n });\n}\n\n/**\n * Scores 1 if the agent did NOT call the specified tool.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.didNotCall('delete_user');\n * ```\n */\nexport function didNotCall(toolName: string) {\n return createScorer({\n id: 'check-did-not-call',\n name: 'Did Not Call Check',\n description: `Checks that \"${toolName}\" was NOT called`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n const { tools } = extractToolCalls(run.output);\n const count = tools.filter(t => t === toolName).length;\n return { toolName, count, passed: count === 0 };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.passed ? 1 : 0;\n });\n}\n\n/**\n * Scores 1 if the tools were called in the specified order (relaxed: allows other calls in between).\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.toolOrder(['search', 'summarize', 'respond']);\n * ```\n */\nexport function toolOrder(expectedOrder: string[]) {\n return createScorer({\n id: 'check-tool-order',\n name: 'Tool Order Check',\n description: `Checks tool call order: [${expectedOrder.join(' → ')}]`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n const { tools } = extractToolCalls(run.output);\n // Check that expectedOrder appears as a subsequence of tools\n let orderIndex = 0;\n for (const tool of tools) {\n if (orderIndex < expectedOrder.length && tool === expectedOrder[orderIndex]) {\n orderIndex++;\n }\n }\n const passed = orderIndex === expectedOrder.length;\n return { actualTools: tools, expectedOrder, passed };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.passed ? 1 : 0;\n });\n}\n\n/**\n * Scores 1 if the agent used no more than `max` tool calls.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.maxToolCalls(5);\n * ```\n */\nexport function maxToolCalls(max: number) {\n return createScorer({\n id: 'check-max-tool-calls',\n name: 'Max Tool Calls Check',\n description: `Checks that no more than ${max} tool calls were made`,\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n const { tools } = extractToolCalls(run.output);\n return { count: tools.length, max, passed: tools.length <= max };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.passed ? 1 : 0;\n });\n}\n\n/**\n * Scores 1 if the agent made no tool calls at all.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.usedNoTools();\n * ```\n */\nexport function usedNoTools() {\n return createScorer({\n id: 'check-used-no-tools',\n name: 'Used No Tools Check',\n description: 'Checks that no tools were called',\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n const { tools } = extractToolCalls(run.output);\n return { count: tools.length, passed: tools.length === 0 };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.passed ? 1 : 0;\n });\n}\n\n/**\n * Scores 1 if none of the tool invocations resulted in an error state.\n * Checks for tool invocations with state other than 'result' (i.e., missing results).\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n * const scorer = checks.noToolErrors();\n * ```\n */\nexport function noToolErrors() {\n return createScorer({\n id: 'check-no-tool-errors',\n name: 'No Tool Errors Check',\n description: 'Checks that no tool calls resulted in errors',\n type: 'agent',\n })\n .preprocess(async ({ run }) => {\n const invocations = extractRawInvocations(run.output);\n const errorCount = invocations.filter(inv => inv.state === 'call' || (inv.result && inv.result.error)).length;\n return { errorCount, totalCalls: invocations.length, passed: errorCount === 0 };\n })\n .generateScore(({ results }) => {\n return results.preprocessStepResult?.passed ? 1 : 0;\n });\n}\n\n// ─── Internal helpers ──────────────────────────────────────────────────────────\n\nfunction extractRawInvocations(output: Parameters<typeof extractToolCalls>[0]) {\n const invocations: any[] = [];\n for (const message of output) {\n const legacy = message?.content?.toolInvocations;\n const fromParts = legacy\n ? undefined\n : (message?.content as any)?.parts\n ?.filter((p: any) => p.type === 'tool-invocation')\n .map((p: any) => p.toolInvocation);\n for (const inv of legacy ?? fromParts ?? []) {\n if (inv) invocations.push(inv);\n }\n }\n return invocations;\n}\n\n// ─── Convenience namespace ────────────────────────────────────────────────────\n\n/**\n * Quick Checks — composable micro-scorers for common assertions.\n *\n * These are zero-LLM, zero-ceremony scorers that plug into the existing\n * `scorers: [...]` array anywhere scorers are used. Internally they are\n * standard `createScorer()` instances with the same observability, storage,\n * and pipeline integration as any other scorer.\n *\n * @example\n * ```ts\n * import { checks } from '@mastra/evals';\n *\n * await runEvals({\n * data: [...],\n * target: myAgent,\n * scorers: [\n * checks.includes('sunny'),\n * checks.calledTool('get_weather'),\n * checks.toolOrder(['search', 'summarize']),\n * checks.noToolErrors(),\n * ],\n * });\n * ```\n */\nexport const checks = {\n includes,\n excludes,\n equals,\n matches,\n similarity,\n calledTool,\n didNotCall,\n toolOrder,\n maxToolCalls,\n usedNoTools,\n noToolErrors,\n};\n"],"mappings":";;;;;;;;;;;;;AAoBA,SAAgB,SAAS,UAAkB,UAA2B,CAAC,GAAG;CACxE,MAAM,EAAE,aAAa,SAAS;CAC9B,OAAO,aAAa;EAClB,IAAI;EACJ,MAAM;EACN,aAAa,8BAA8B,SAAS;EACpD,MAAM;CACR,CAAC,CAAC,CACC,WAAW,OAAO,EAAE,UAAU;EAC7B,IAAI,SAAS,IAAI,OACd,QAAO,MAAK,EAAE,SAAS,WAAW,CAAC,CACnC,KAAI,MAAK,kCAAkC,CAAC,CAAC,CAAC,CAC9C,KAAK,GAAG;EACX,IAAI,SAAS;EACb,IAAI,YAAY;GACd,SAAS,OAAO,YAAY;GAC5B,SAAS,OAAO,YAAY;EAC9B;EACA,OAAO;GAAE;GAAQ;GAAQ,OAAO,OAAO,SAAS,MAAM;EAAE;CAC1D,CAAC,CAAC,CACD,eAAe,EAAE,cAAc;EAC9B,OAAO,QAAQ,sBAAsB,QAAQ,IAAI;CACnD,CAAC;AACL;;;;;;;;;;AAWA,SAAgB,SAAS,UAAkB,UAA2B,CAAC,GAAG;CACxE,MAAM,EAAE,aAAa,SAAS;CAC9B,OAAO,aAAa;EAClB,IAAI;EACJ,MAAM;EACN,aAAa,wCAAwC,SAAS;EAC9D,MAAM;CACR,CAAC,CAAC,CACC,WAAW,OAAO,EAAE,UAAU;EAC7B,IAAI,SAAS,IAAI,OACd,QAAO,MAAK,EAAE,SAAS,WAAW,CAAC,CACnC,KAAI,M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