@mastra/evals 1.10.2 → 1.10.4-alpha.0

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.
@@ -426,7 +426,7 @@ const analyzeOutputSchema$7 = {
426
426
  "type": "object",
427
427
  "properties": {
428
428
  "groundTruthUnit": { "type": "string" },
429
- "outputUnit": { "anyOf": [{ "type": "string" }, { "type": "null" }] },
429
+ "outputUnit": { "type": ["string", "null"] },
430
430
  "matchType": {
431
431
  "type": "string",
432
432
  "enum": [
@@ -757,10 +757,11 @@ function createFaithfulnessScorer({ model, options }) {
757
757
  });
758
758
  }
759
759
  }).generateScore(({ results }) => {
760
- const totalClaims = results.analyzeStepResult.verdicts.length;
761
- const supportedClaims = results.analyzeStepResult.verdicts.filter((v) => v.verdict === "yes").length;
760
+ const verdicts = results.analyzeStepResult.verdicts;
761
+ const totalClaims = results.preprocessStepResult?.claims?.length || verdicts.length;
762
+ const supportedClaims = verdicts.filter((v) => v.verdict.toLowerCase().trim() === "yes").length;
762
763
  if (totalClaims === 0) return 0;
763
- return roundToTwoDecimals(supportedClaims / totalClaims * (options?.scale || 1));
764
+ return roundToTwoDecimals(Math.min(1, supportedClaims / totalClaims) * (options?.scale || 1));
764
765
  }).generateReason({
765
766
  description: "Reason about the results",
766
767
  createPrompt: ({ run, results, score }) => {
@@ -1184,10 +1185,11 @@ function createHallucinationScorer({ model, options }) {
1184
1185
  });
1185
1186
  }
1186
1187
  }).generateScore(({ results }) => {
1187
- const totalStatements = results.analyzeStepResult.verdicts.length;
1188
- const contradictedStatements = results.analyzeStepResult.verdicts.filter((v) => v.verdict === "yes").length;
1188
+ const verdicts = results.analyzeStepResult.verdicts;
1189
+ const totalStatements = results.preprocessStepResult?.claims?.length || verdicts.length;
1190
+ const contradictedStatements = verdicts.filter((v) => v.verdict.toLowerCase().trim() === "yes").length;
1189
1191
  if (totalStatements === 0) return 0;
1190
- return roundToTwoDecimals(contradictedStatements / totalStatements * (options?.scale || 1));
1192
+ return roundToTwoDecimals(Math.min(1, contradictedStatements / totalStatements) * (options?.scale || 1));
1191
1193
  }).generateReason({
1192
1194
  description: "Reason about the results",
1193
1195
  createPrompt: async ({ run, results, score }) => {