{"record":{"id":"ab858b186f7a5a2f","repo":"mastra-ai/mastra","slug":"invalid-scorer-threshold","errorCode":"INVALID_SCORER_THRESHOLD","errorMessage":"${label} threshold for scorer \"${scorerId}\" must be a finite number between 0 and 1, got ${value}","messagePattern":"(.+?) threshold for scorer \"(.+?)\" must be a finite number between 0 and 1, got (.+?)","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/evals/thresholds.ts","lineNumber":34,"sourceCode":"export function checkThresholdPassed(score: number, threshold: ThresholdConfig): boolean {\n  if (!Number.isFinite(score)) {\n    return false;\n  }\n  if (typeof threshold === 'number') {\n    return score >= threshold;\n  }\n  if (threshold.min !== undefined && score < threshold.min) return false;\n  if (threshold.max !== undefined && score > threshold.max) return false;\n  return true;\n}\n\nexport function isScorerWithThreshold<TScorer>(entry: ScorerEntry<TScorer>): entry is ScorerWithThreshold<TScorer> {\n  return typeof entry === 'object' && entry !== null && 'scorer' in entry && 'threshold' in entry;\n}\n\nfunction validateThresholdBound(value: number, label: string, scorerId: string): void {\n  if (!Number.isFinite(value) || value < 0 || value > 1) {\n    throw new MastraError({\n      domain: 'SCORER',\n      id: 'INVALID_SCORER_THRESHOLD',\n      category: 'USER',\n      text: `${label} threshold for scorer \"${scorerId}\" must be a finite number between 0 and 1, got ${value}`,\n    });\n  }\n}\n\nexport function validateThresholdConfig(threshold: ThresholdConfig, scorerId: string): void {\n  if (typeof threshold === 'number') {\n    validateThresholdBound(threshold, 'Minimum', scorerId);\n    return;\n  }\n  if (typeof threshold !== 'object' || threshold === null || Array.isArray(threshold)) {\n    throw new MastraError({\n      domain: 'SCORER',\n      id: 'INVALID_SCORER_THRESHOLD',\n      category: 'USER',","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/evals/thresholds.ts#L16-L52","documentation":"An INVALID_SCORER_THRESHOLD MastraError (domain SCORER, category USER) thrown by validateThresholdBound when a configured scorer threshold is not a finite number in [0, 1]. Thresholds compare scores to decide pass/fail, so out-of-range or non-finite values are rejected at configuration time.","triggerScenarios":"Defining a scorer entry with `threshold: -0.1`, `threshold: 1.5`, `threshold: NaN`, `threshold: Infinity`, or a non-numeric value coerced into a number field, then validating the threshold config via validateThresholdConfig.","commonSituations":"Typo in the threshold value; computing a threshold with a formula that yields NaN (e.g. division by zero) or a percentage (0-100) instead of a fraction (0-1); loading thresholds from env/JSON with wrong units.","solutions":["Set the threshold to a finite number between 0 and 1 (e.g. 0.7, not 70)","If loading from config/env, parse and clamp/validate: Number.isFinite(v) && v >= 0 && v <= 1","Check any threshold computation for NaN sources (division by zero, undefined inputs)"],"exampleFix":"// before\nagents: { myAgent: { scoring: { myScorer: { threshold: 70 } } } }\n// after\nagents: { myAgent: { scoring: { myScorer: { threshold: 0.7 } } } }","handlingStrategy":"validation","validationCode":"function assertThreshold(v: unknown, label: string, scorerId: string): asserts v is number {\n  if (typeof v !== 'number' || !Number.isFinite(v) || v < 0 || v > 1) {\n    throw new Error(`${label} threshold for \"${scorerId}\" must be a finite number in [0,1], got ${v}`);\n  }\n}","typeGuard":"function isValidThreshold(v: unknown): v is number {\n  return typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 1;\n}","tryCatchPattern":"try {\n  validateThresholdConfig(scorerEntries);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'INVALID_SCORER_THRESHOLD') {\n    logger.error('Bad scorer threshold in config', { detail: e.message });\n  } else throw e;\n}","preventionTips":["Use fractions (0-1), not percentages, for thresholds","Clamp/validate thresholds loaded from env or config files","Guard computed thresholds against NaN (division by zero, undefined)","Type thresholds as number and validate at config-load time"],"tags":["scorer","threshold","config-validation","mastra-error"],"backgroundTag":"invalid-scorer-threshold","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}