linshenkx/prompt-optimizer · error · EvaluationParseError

Invalid numeric score for "${fieldName}": ${value}

Error message

Invalid numeric score for "${fieldName}": ${value}

What it means

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.

Source

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

    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 {
        return null;
      }
    };

    const toDimension = (key: string, label: string, scoreValue: any): EvaluationDimension | null => {
      const score = tryExtractScore(scoreValue, `dimension.${key}`);
      if (score === null) return null;
      return { key, label: label || key, score };
    };

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Instruct the model to emit integers 0-100 only, with an example JSON in the prompt
  2. If qualitative labels are expected, map them (A=95, high=90, etc.) before invoking the service or in a post-processing step
  3. Retry with temperature 0 and an explicit schema; consider a stronger judge model

Example fix

// prompt (before)
Rate each dimension.

// after
For each dimension output an integer 0-100, e.g. {"accuracy": 92}. Never use words or letter grades.
Defensive patterns

Strategy: validation

Validate before calling

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)); };
const normalized = dims.map(d => ({ ...d, score: toScore(raw[d.name]) ?? fallbackScore(d.name) }));

Type guard

const isNumericScore = (v: unknown): v is number | `${number}` | string => typeof v === 'number' || (/^\s*\d/.test(String(v)));

Prevention

When it happens

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

Common situations: 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.

Related errors


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