alibaba/spring-ai-alibaba · error · BizException
INVALID_PARAMS
INVALID_PARAMS
Error message
expected type is ${type} but not match the current value type. What it means
VariableUtils.convertValueByType converts a raw variable value (string/JSON) into the declared target type. When conversion fails — bad JSON, wrong shape, incompatible value — the catch block (or the fall-through) throws BizException with code INVALID_PARAMS naming the expected type.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/utils/common/VariableUtils.java:323
else if (ParameterTypeEnum.ARRAY_BOOLEAN.getCode().equals(type)) {
if (value instanceof List) {
return value;
}
else if (value instanceof String) {
return JsonUtils.fromJsonToList((String) value, Boolean.class);
}
}
else if (ParameterTypeEnum.ARRAY_FILE.getCode().equals(type)) {
if (value instanceof List) {
return value;
}
else if (value instanceof String) {
return JsonUtils.fromJsonToList((String) value, File.class);
}
}
}
catch (Exception e) {
throw new BizException(ErrorCode.INVALID_PARAMS.toError(key,
"expected type is " + type + " but not match the current value type."));
}
throw new BizException(ErrorCode.INVALID_PARAMS.toError(key,
"expected type is " + type + " but not match the current value type."));
}
/**
* Identifies variables from text content (ordered, non-unique)
*/
public static List<String> identifyVariableListFromText(String content) {
List<String> result = Lists.newArrayList();
if (StringUtils.isBlank(content)) {
return result;
}
Matcher matcher = VAR_EXPR_PATTERN.matcher(content);
// 查找并添加匹配的内容
while (matcher.find()) {
result.add(matcher.group(1));View on GitHub (pinned to f82da0b50f)
Solutions
- Log/inspect the actual value and the declared type; fix the value to match the expected type
- Validate/parse the value with JsonUtils before assignment to catch malformed JSON early
- Correct the variable's declared type to match the real data shape
- Wrap the call site in a try-catch for BizException and surface a user-friendly message identifying the offending key
Example fix
// before
Object v = VariableUtils.convertValueByType("ids", "List", "not-json");
// after
String raw = "[\"a\",\"b\"]";
if (!JsonUtils.isJsonArray(raw)) {
throw new IllegalArgumentException("ids must be a JSON array");
}
Object v = VariableUtils.convertValueByType("ids", "List", raw); Defensive patterns
Strategy: try-catch
Validate before calling
boolean canConvert(String type, Object value) {
try {
VariableUtils.convertValueByType("__probe__", type, value);
return true;
} catch (Exception e) {
return false;
}
} Type guard
boolean isJsonString(Object v) { return v instanceof String s && (s.startsWith("{") || s.startsWith("[")); } Try / catch
try {
Object v = VariableUtils.convertValueByType(key, type, value);
} catch (BizException e) {
if (ErrorCode.INVALID_PARAMS.name().equals(e.getCode())) {
log.warn("Variable {} cannot be converted to {}: {}", key, type, value);
}
} Prevention
- Declare variable types to match actual upstream output
- JSON-encode structured values before assignment
- Probe-convert in tests for all workflow variable mappings
When it happens
Trigger: Calling convertValueByType with a value that cannot be converted to the requested type: non-JSON string for a list/object target, numeric string for a non-numeric type, malformed File JSON for File targets, or null/unconvertible input reaching the final throw.
Common situations: Workflow variable substitution where upstream node output type differs from declared variable type; users typing values in admin UI forms that don't match configured types; JSON stored with extra quoting or truncation.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/3d9263043e5f723d.
Report an issue: GitHub.