linshenkx/prompt-optimizer · error · EvaluationParseError

Evaluation result is not a valid object.

Error message

Evaluation result is not a valid object.

What it means

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.

Solutions

  1. Log the raw content and the extracted data to see the actual shape returned
  2. Adjust the judge prompt to return a full JSON object with a score field
  3. Wrap in retry with stricter instructions or a different judge model
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) skipOrFlag(rawContent);

Type guard

function isScoreObject(v: unknown): v is Record<string, unknown> { return typeof v === 'object' && v !== null && !Array.isArray(v); }

Try / catch

try { ... } catch (e) { if (e instanceof EvaluationParseError) { /* log raw content, adjust prompt, retry once */ } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Models answering with only the score; extraction regex capturing a JSON scalar; prompt template changed so the model returns a different top-level shape.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/71a6918ae47479c6. Report an issue: GitHub.

Appendix: source

Thrown at packages/core/src/services/evaluation/service.ts:3113

        if (depth === 0) {
          return content.slice(start, i + 1);
        }
      }
    }

    return null;
  }

  /**
   * 标准化评估响应(统一结构)
   */
  private normalizeEvaluationResponse(
    data: any,
    type: EvaluationType,
    metadata?: EvaluationResponse['metadata']
  ): EvaluationResponse {
    if (!data || typeof data !== 'object') {
      throw new EvaluationParseError('Evaluation result is not a valid object.');
    }

    if (data.score === undefined || data.score === null) {
      throw new EvaluationParseError('Evaluation result is missing the "score" field.');
    }

    // 提取分数(0-100,整数)
    const extractScore = (value: any, fieldName: string): number => {
      if (value === undefined || value === null) {
        throw new EvaluationParseError(`Evaluation result is missing score for "${fieldName}".`);
      }
      const num = typeof value === 'number' ? value : parseInt(String(value));
      if (isNaN(num)) {
        throw new EvaluationParseError(`Invalid numeric score for "${fieldName}": ${value}`);
      }
      return Math.max(0, Math.min(100, num));
    };

View on GitHub (pinned to 3e677b1d9f)