alibaba/spring-ai-alibaba · error · IllegalArgumentException
参数 的值 ' ' 不是有效的数值
Error message
参数 %s 的值 '%s' 不是有效的数值
What it means
An IllegalArgumentException thrown by validateNumericValue (invoked from validateParameterTypes) when a model parameter declared as numeric receives a String value that cannot be parsed by Double.parseDouble. The message names the offending parameter and its value.
Solutions
- Convert the value to a valid number before storing/passing it (use '.' decimal separator, no units).
- Parse with the intended locale first, or normalize the string (trim, replace ',' with '.') prior to validation.
- Fix the parameter's declared type if it is genuinely not numeric so validateParameterTypes skips it.
- Catch IllegalArgumentException in the caller and surface a field-level message naming the parameter.
Example fix
// before
params.put("temperature", "0,7"); // '0,7' -> Double.parseDouble fails
parser.validateModelConfig(info);
// after
params.put("temperature", Double.parseDouble("0,7".replace(',', '.')));
parser.validateModelConfig(info); // ok Defensive patterns
Strategy: validation
Validate before calling
Object v = params.get(name);
if (v instanceof String s) { try { Double.parseDouble(s.trim().replace(',', '.')); } catch (NumberFormatException e) { throw new BadRequestException("parameter " + name + " must be numeric"); } } Type guard
boolean isNumericValue = v instanceof Number || (v instanceof String s && s.matches("\\s*-?\\d+(\\.\\d+)?([eE][+-]?\\d+)?\\s*")); Try / catch
try { parser.validateModelConfig(info); } catch (IllegalArgumentException e) { if (e.getMessage().contains("不是有效的数值")) { /* fix the named parameter */ } throw e; } Prevention
- Store numeric parameters as JSON numbers, not strings
- Normalize locale-specific decimal separators on input
- Strip units/symbols from user-entered numbers before saving
When it happens
Trigger: Calling validateModelConfig where a parameter known to be numeric (e.g. temperature, top_p) is supplied as a non-numeric string like 'hot', '0,7' (comma decimal separator), or '0.7 ' with stray characters. Non-String, non-Number values take the separate '应该是数值类型' branch instead.
Common situations: User-entered parameters from a form stored as strings; locale-formatted numbers using ',' as decimal separator; copied values with units ('0.9f', '70%'); schema drift after parameter type changes.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- must be at least , got
- requires
- AgentCard or AgentCardProvider must be provided
- AgentScope Model must be provided for AgentScope routing…
- AgentScope routing flow requires at least one sub-agent
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/7689925aad382cde.
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/utils/ModelConfigParser.java:253
}
/**
* 验证数值类型的参数值
*
* @param parameterName 参数名
* @param value 参数值
*/
private void validateNumericValue(String parameterName, Object value) {
if (value instanceof Number) {
return; // 已经是数值类型
}
if (value instanceof String) {
try {
Double.parseDouble((String) value);
return; // 可以转换为数值
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
String.format("参数 %s 的值 '%s' 不是有效的数值", parameterName, value));
}
}
throw new IllegalArgumentException(String.format("参数 %s 的值 '%s' 应该是数值类型", parameterName, value));
}
}
View on GitHub (pinned to f82da0b50f)