{"record":{"id":"0144cf0cd81100ad","repo":"linshenkx/prompt-optimizer","slug":"invalid-numeric-score-for-fieldname-value","errorCode":null,"errorMessage":"Invalid numeric score for \"${fieldName}\": ${value}","messagePattern":"Invalid numeric score for \"(.+?)\": (.+?)","errorType":"exception","errorClass":"EvaluationParseError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":3127,"sourceCode":"    type: EvaluationType,\n    metadata?: EvaluationResponse['metadata']\n  ): EvaluationResponse {\n    if (!data || typeof data !== 'object') {\n      throw new EvaluationParseError('Evaluation result is not a valid object.');\n    }\n\n    if (data.score === undefined || data.score === null) {\n      throw new EvaluationParseError('Evaluation result is missing the \"score\" field.');\n    }\n\n    // 提取分数（0-100，整数）\n    const extractScore = (value: any, fieldName: string): number => {\n      if (value === undefined || value === null) {\n        throw new EvaluationParseError(`Evaluation result is missing score for \"${fieldName}\".`);\n      }\n      const num = typeof value === 'number' ? value : parseInt(String(value));\n      if (isNaN(num)) {\n        throw new EvaluationParseError(`Invalid numeric score for \"${fieldName}\": ${value}`);\n      }\n      return Math.max(0, Math.min(100, num));\n    };\n\n    const tryExtractScore = (value: any, fieldName: string): number | null => {\n      try {\n        return extractScore(value, fieldName);\n      } catch {\n        return null;\n      }\n    };\n\n    const toDimension = (key: string, label: string, scoreValue: any): EvaluationDimension | null => {\n      const score = tryExtractScore(scoreValue, `dimension.${key}`);\n      if (score === null) return null;\n      return { key, label: label || key, score };\n    };\n","sourceCodeStart":3109,"sourceCodeEnd":3145,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L3109-L3145","documentation":"EvaluationParseError thrown by extractScore when a score value exists but cannot be converted to a number — typeof is not number and parseInt(String(value)) yields NaN. Examples: \"good\", true, or an empty-ish string. Note parseInt accepts prefixed digits (\"85\" or \"85abc\" parse to 85), so this fires only when no leading digits exist.","triggerScenarios":"A score or dimension score is a non-numeric string like \"N/A\", \"high\", a boolean, or an object; parseInt of its string form returns NaN.","commonSituations":"Judge model answering with letter grades or qualitative labels instead of 0-100 numbers; locale-specific numbers handled elsewhere; model returning true/false for pass/fail dimensions.","solutions":["Instruct the model to emit integers 0-100 only, with an example JSON in the prompt","If qualitative labels are expected, map them (A=95, high=90, etc.) before invoking the service or in a post-processing step","Retry with temperature 0 and an explicit schema; consider a stronger judge model"],"exampleFix":"// prompt (before)\nRate each dimension.\n\n// after\nFor each dimension output an integer 0-100, e.g. {\"accuracy\": 92}. Never use words or letter grades.","handlingStrategy":"validation","validationCode":"const toScore = (v: unknown): number | null => { const n = typeof v === 'number' ? v : parseInt(String(v ?? ''), 10); return Number.isNaN(n) ? null : Math.max(0, Math.min(100, n)); };\nconst normalized = dims.map(d => ({ ...d, score: toScore(raw[d.name]) ?? fallbackScore(d.name) }));","typeGuard":"const isNumericScore = (v: unknown): v is number | `${number}` | string => typeof v === 'number' || (/^\\s*\\d/.test(String(v)));","tryCatchPattern":null,"preventionTips":["Prompt for integers 0-100 only with an example payload","Map qualitative labels to numbers upstream if your judge emits them","Reject/normalize non-numeric scores before handing results to the service"],"tags":["evaluation","parsing","score","type-coercion"],"backgroundTag":"llm-output-parse-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}