linshenkx/prompt-optimizer · error · EvaluationParseError

Evaluation result is missing the "score" field.

Error message

Evaluation result is missing the "score" field.

What it means

EvaluationParseError thrown when the evaluation result object exists but has no score field (score is undefined or null). score is the mandatory top-level field the normalizer reads; without it the evaluation cannot be quantified. Distinguish from error 56 (not an object) and 58 (nested dimension score missing).

Source

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

    }

    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));
    };

    const tryExtractScore = (value: any, fieldName: string): number | null => {
      try {
        return extractScore(value, fieldName);
      } catch {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Fix the judge prompt to output the literal key "score"
  2. Check for near-miss keys (overall/rating) in the raw payload and confirm the parser contract
  3. Retry with temperature 0 and an explicit output schema example in the prompt

Example fix

// prompt instruction (before)
Return your assessment as JSON with an overall grade.

// after
Return JSON exactly like: { "score": <0-100>, "reasoning": "..." }
Defensive patterns

Strategy: validation

Validate before calling

if (!('score' in parsed) || parsed.score == null) { parsed.score = parsed.overall ?? parsed.rating; } // pre-map common aliases

Type guard

const hasScore = (v: unknown): v is { score: number | string } => { const s = (v as any)?.score; return s !== undefined && s !== null; };

Prevention

When it happens

Trigger: Judge model returns valid JSON like {"reasoning": "..."} or {"overall": 90} without the exact key 'score'; or score is explicitly null.

Common situations: Key naming drift between prompt template and parser (overall vs score, rating vs score); model omitting the field; older prompts predating the score-based schema.

Related errors


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