{"record":{"id":"1643bdcd7df30130","repo":"mastra-ai/mastra","slug":"createmultiturnjudgescorer-options-scale-must-be","errorCode":null,"errorMessage":"createMultiTurnJudgeScorer: options.scale must be a finite number","messagePattern":"createMultiTurnJudgeScorer: options\\.scale must be a finite number","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/evals/src/scorers/llm/multi-turn-judge/index.ts","lineNumber":89,"sourceCode":" * ```\n *\n * To persist scores, register an instance under the same id on the Mastra instance. Only the id is\n * used to resolve scorer metadata, so the registered instance's `criterion` can be a placeholder.\n */\nexport function createMultiTurnJudgeScorer({\n  model,\n  criterion,\n  options,\n}: {\n  model: MastraModelConfig;\n  /** What the conversation must satisfy, in plain English. */\n  criterion: string;\n  options?: MultiTurnJudgeScorerOptions;\n}) {\n  const scale = options?.scale ?? 1;\n\n  if (!Number.isFinite(scale)) {\n    throw new Error('createMultiTurnJudgeScorer: options.scale must be a finite number');\n  }\n\n  return createScorer<ScorerRunInputForLLMJudge, ScorerRunOutputForLLMJudge>({\n    id: 'multi-turn-judge-scorer',\n    name: 'Multi-turn Judge (LLM)',\n    description: 'Grades every assistant turn of a conversation against a plain-English criterion',\n    judge: {\n      model,\n      instructions: MULTI_TURN_JUDGE_INSTRUCTIONS,\n    },\n  })\n    .analyze({\n      description: 'Judge the whole conversation against the criterion',\n      outputSchema: analyzeOutputSchema,\n      createPrompt: ({ run }) => createAnalyzePrompt({ criterion, turns: getAssistantTurns(run.output) }),\n    })\n    .generateScore(({ results }) => {\n      const analysis = results.analyzeStepResult as MultiTurnJudgeAnalysisResult | undefined;","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/evals/src/scorers/llm/multi-turn-judge/index.ts#L71-L107","documentation":"createMultiTurnJudgeScorer defaults options.scale to 1 but rejects any value that is not a finite number (NaN, Infinity, -Infinity, or a non-numeric value coerced into the check). The scale defines the numeric range the LLM judge grades against, so an invalid scale would produce meaningless scores.","triggerScenarios":"Calling createMultiTurnJudgeScorer({ criterion, options: { scale: Number.NaN } }) or { scale: Infinity }; commonly a value read from a config file or parsed string (e.g. parseFloat('10/5')) yields NaN/Infinity.","commonSituations":"Loading scale from an env var or JSON config without validating the parse; dividing by zero upstream producing Infinity; passing a string '5' from CLI args instead of the number 5.","solutions":["Pass an explicit finite numeric scale, e.g. { scale: 5 }","Validate config values with Number.isFinite(scale) before constructing the scorer","Coerce string inputs with Number() and reject NaN before use","Omit scale entirely to use the default of 1"],"exampleFix":"// before\nconst scale = parseFloat(process.env.JUDGE_SCALE); // NaN if unset\nconst scorer = createMultiTurnJudgeScorer({ criterion, options: { scale } });\n// after\nconst scale = process.env.JUDGE_SCALE ? Number(process.env.JUDGE_SCALE) : undefined;\nif (scale !== undefined && !Number.isFinite(scale)) throw new Error('JUDGE_SCALE must be a finite number');\nconst scorer = createMultiTurnJudgeScorer({ criterion, options: scale !== undefined ? { scale } : undefined });","handlingStrategy":"validation","validationCode":"const scale = options?.scale ?? 1;\nif (!Number.isFinite(scale)) throw new Error(`Invalid judge scale: ${scale}`);","typeGuard":"function isValidScale(s) {\n  return typeof s === 'number' && Number.isFinite(s) && s > 0;\n}","tryCatchPattern":"try {\n  const scorer = createMultiTurnJudgeScorer({ criterion, options });\n} catch (e) {\n  if (e.message.includes('scale must be a finite number')) {\n    throw new Error(`Bad config: scale=${options?.scale} is not finite`, { cause: e });\n  }\n  throw e;\n}","preventionTips":["Parse numeric config with Number() and validate immediately at the config boundary","Use zod or similar to validate scale as a finite positive number in config schemas","Never pass raw env-var strings as numeric options"],"tags":["configuration","validation","evals","nan"],"backgroundTag":"invalid-numeric-config","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}