{"record":{"id":"71a6918ae47479c6","repo":"linshenkx/prompt-optimizer","slug":"evaluation-result-is-not-a-valid-object","errorCode":null,"errorMessage":"Evaluation result is not a valid object.","messagePattern":"Evaluation result is not a valid object\\.","errorType":"exception","errorClass":"EvaluationParseError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":3113,"sourceCode":"        if (depth === 0) {\n          return content.slice(start, i + 1);\n        }\n      }\n    }\n\n    return null;\n  }\n\n  /**\n   * 标准化评估响应（统一结构）\n   */\n  private normalizeEvaluationResponse(\n    data: any,\n    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","sourceCodeStart":3095,"sourceCodeEnd":3131,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L3095-L3131","documentation":"EvaluationParseError thrown during normalizeEvaluationResponse when the parsed evaluation payload is not a plain object (null, array, primitive, or undefined). This guards the normalization step that expects an object containing at least a score. It indicates the extracted JSON, while parseable, is not an evaluation result object.","triggerScenarios":"The judge model returns a bare number/string (e.g. just \"85\") or an array, and it is fed into normalization; or JSON extraction grabs a non-object fragment from the output.","commonSituations":"Models answering with only the score; extraction regex capturing a JSON scalar; prompt template changed so the model returns a different top-level shape.","solutions":["Log the raw content and the extracted data to see the actual shape returned","Adjust the judge prompt to return a full JSON object with a score field","Wrap in retry with stricter instructions or a different judge model"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) skipOrFlag(rawContent);","typeGuard":"function isScoreObject(v: unknown): v is Record<string, unknown> { return typeof v === 'object' && v !== null && !Array.isArray(v); }","tryCatchPattern":"try { ... } catch (e) { if (e instanceof EvaluationParseError) { /* log raw content, adjust prompt, retry once */ } else throw e; }","preventionTips":["Prompt the judge to return a JSON object, never a bare value","Validate extracted JSON shape before passing to normalization"],"tags":["evaluation","parsing","type-validation"],"backgroundTag":"llm-output-parse-failed","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}