jd-opensource/joyagent-jdgenie · error · RuntimeException
不支持的模型类型
Error message
不支持的模型类型
What it means
Nl2SqlService.getTableName(ChatModelInfoDto) maps a model type to a table reference for querying: 'table' yields the content as-is, 'sql' wraps content as a subquery '(content) t'. Any other type throws this RuntimeException, blocking queryData execution for that model.
Solutions
- Set the ChatModelInfoDto type to 'table' or 'sql'
- Correct the model record in the model management storage before running queries
- Include the model id/type in the exception message to speed diagnosis
Example fix
// before
throw new RuntimeException("不支持的模型类型" + modelInfo.getType());
// after
throw new RuntimeException("不支持的模型类型[" + modelInfo.getType() + "], 仅支持 table/sql"); Defensive patterns
Strategy: validation
Validate before calling
String type = dto.getType();
if (!"table".equalsIgnoreCase(type) && !"sql".equalsIgnoreCase(type)) {
throw new IllegalArgumentException("unsupported model type: " + type);
}
String tableName = nl2SqlService.getTableName(dto); Try / catch
try {
String t = nl2SqlService.getTableName(dto);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("不支持的模型类型")) {
log.error("bad model type for query: {}", e.getMessage());
// skip this model or fail the query with a clear message
}
throw e;
} Prevention
- Enforce the table/sql type enum when creating model DTOs
- Share one type constant/enum across services
- Validate types before building NL2SQL requests
When it happens
Trigger: queryData() processing NL2SQLResult data referencing a ChatModelInfoDto whose type is neither 'table' nor 'sql'.
Common situations: Model metadata maintained with unsupported type values; drift between the model registry and the two types this service supports; type field null in the DTO.
Related errors
AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08).
Data as JSON: /api/errors/e0f76b0d23ba50d3.
Report an issue: GitHub.
Appendix: source
Thrown at genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java:120
}
if (CollectionUtils.isEmpty(nl2SQLResult.getData())) {
throw new RuntimeException("nl2sql返回为空");
}
nl2SQLResult.setRootQuery(request.getQuery());
for (NL2SQLResult.NL2SQLData nl2SQLData : nl2SQLResult.getData()) {
String prettySql = replaceFirstMatchedOrThrow(nl2SQLData.getNl2sql(), request.getModelCodeList());
nl2SQLData.setNl2sql(prettySql);
}
return queryData(request, nl2SQLResult);
}
public String getTableName(ChatModelInfoDto modelInfo) {
if ("table".equalsIgnoreCase(modelInfo.getType())) {
return modelInfo.getContent();
} else if ("sql".equalsIgnoreCase(modelInfo.getType())) {
return "(" + modelInfo.getContent() + ") t";
} else {
throw new RuntimeException("不支持的模型类型" + modelInfo.getType());
}
}
public List<ChatQueryData> queryData(NL2SQLReq request, NL2SQLResult nl2SQLResult) throws Exception {
List<NL2SQLResult.NL2SQLData> data = nl2SQLResult.getData();
List<ChatQueryData> dataList = new ArrayList<>();
List<ChatModelInfoDto> schemaInfo = request.getSchemaInfo();
Map<String, ChatModelInfoDto> modelMap = schemaInfo.stream().collect(Collectors.toMap(ChatModelInfoDto::getModelCode, v -> v));
for (NL2SQLResult.NL2SQLData nl2SQLData : data) {
SqlModel sqlModel = SqlParserUtils.parseSelectSql(nl2SQLData.getNl2sql(), dataAgentConfig.getDbConfig().getType());
String modelCode = sqlModel.getFromTable().getTableName();
ChatModelInfoDto modelInfo = modelMap.get(modelCode);
if (modelInfo == null) {
throw new RuntimeException("modelCode:" + modelCode + "不存在");
}
Map<String, ChatSchemaDto> columnMap = modelInfo.getSchemaList().stream().collect(Collectors.toMap(ChatSchemaDto::getColumnId, t -> t));
List<ChatQueryColumn> chatQueryColumns = parseColumns(sqlModel, columnMap);
List<ChatQueryFilter> chatQueryFilters = parseFilters(sqlModel, columnMap);View on GitHub (pinned to 2417e0b8b6)