alibaba/spring-ai-alibaba · error · RuntimeException

解析模型调用结果出错,请重试

Error message

解析模型调用结果出错,请重试

What it means

Thrown by EvaluatorServiceImpl.evaluatorTest after the LLM responds: the model's output string cannot be parsed into EvaluatorDebugResult via fastjson JSONObject.parseObject. The error indicates the model returned something other than the expected JSON structure.

Solutions

  1. Retry the debug call — the message itself says 'please retry' and LLM output is nondeterministic
  2. Strip markdown code fences and extract the first {...} block before parseObject
  3. Enable JSON mode / structured output on the model call and tighten the prompt to mandate exact JSON schema
  4. Inspect the log line '解析失败: {}' to see the raw response and fix the prompt or parser accordingly
  5. Wrap parseObject with a fallback parser or default EvaluatorDebugResult on failure

Example fix

// before
return JSONObject.parseObject(formatedResponse, EvaluatorDebugResult.class);
// after
String json = extractJsonBlock(formatedResponse); // strip ``` fences / surrounding text
try {
    return JSONObject.parseObject(json, EvaluatorDebugResult.class);
} catch (Exception e) {
    throw new EvaluatorResponseParseException("Model returned non-JSON output: " + json, e);
}
Defensive patterns

Strategy: retry

Validate before calling

String json = extractJsonBlock(response);
if (json == null || !json.trim().startsWith("{")) throw new RetryableFormatException(response);

Type guard

boolean looksLikeJson(String s) { return s != null && s.replace("```","").trim().startsWith("{"); }

Try / catch

try { return JSONObject.parseObject(formatedResponse, EvaluatorDebugResult.class); } catch (Exception e) { log.warn("non-JSON model output: {}", formatedResponse); return retryWithStrictJsonPrompt(); }

Prevention

When it happens

Trigger: The evaluator's model prompt yields free-form text, markdown fences (```json ... ```), trailing prose, or truncated JSON; formatedResponse still isn't valid JSON matching EvaluatorDebugResult fields.

Common situations: Weak/older models ignoring strict JSON output instructions; temperature too high; prompt template edited so the JSON schema example was lost; model returning Chinese text where the parser expects typed fields; max_tokens cutting JSON mid-object.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/14d00dc271039ad3. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/EvaluatorServiceImpl.java:190

        String userPrompt = modelConfigParser.replaceVariables(request.getPrompt(), request.getVariables());

        String prompt = userPrompt.concat(SYSTEM_PROMPT);

        log.info("evaluatorTest:prompt,{}", prompt);

        String response = Objects.requireNonNull(client.prompt(prompt).call().content()).trim();

        log.info("模型返回值:{}", response);

        String formatedResponse = extractRawText(response);
        log.info("模型返回值:{},格式化后模型返回值:{}.", response, formatedResponse);

        try {
            return JSONObject.parseObject(formatedResponse, EvaluatorDebugResult.class);
        } catch (Exception e) {
            log.info("解析失败: {}", formatedResponse, e);
            throw new RuntimeException("解析模型调用结果出错,请重试");
        }

    }

} 

View on GitHub (pinned to f82da0b50f)