jd-opensource/joyagent-jdgenie · error · RuntimeException
nl2sql server return error:
Error message
nl2sql server return error:
What it means
nl2sqlQueryData requires the agent to return code==200. Any other code is surfaced as 'nl2sql server return error:' plus the agent's err_msg. This is an application-level error from the nl2sql service, not an HTTP transport failure.
Solutions
- Read err_msg after the prefix — it carries the agent's own failure reason
- Fix the request (query text, model codes, schema) that made the agent return a non-200 code
- Check agent service logs for the corresponding traceId
- Retry only if err_msg indicates a transient agent-side condition
Defensive patterns
Strategy: try-catch
Try / catch
try {
return nl2sqlQueryData(request, result);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("nl2sql server return error:")) {
String agentErrMsg = e.getMessage().substring("nl2sql server return error:".length());
log.error("agent error: {}", agentErrMsg);
}
throw e;
} Prevention
- Surface err_msg to callers so root cause is visible
- Validate query/model inputs before sending to agent
- Monitor agent non-200 rates
When it happens
Trigger: Agent responds with valid JSON whose code != 200 (e.g. 500 on SQL generation failure, 4xx on bad request params like query/model codes).
Common situations: Malformed or too-complex natural language query; agent-side LLM/DB failure; schema metadata missing so the agent cannot generate SQL.
Related errors
AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08).
Data as JSON: /api/errors/addbdbaf752ceef1.
Report an issue: GitHub.
Appendix: source
Thrown at genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java:101
.map(code -> Pattern.compile("(?i)(?<!`)\\b" + Pattern.quote(code) + "\\b(?!`)"))
.toList();
Matcher matcher;
for (Pattern pattern : patterns) {
matcher = pattern.matcher(input);
if (matcher.find()) {
return matcher.replaceFirst("`$0`");
}
}
return input;
}
private List<ChatQueryData> nl2sqlQueryData(NL2SQLReq request, NL2SQLResult nl2SQLResult) throws Exception {
if (nl2SQLResult == null || nl2SQLResult.getCode() == null) {
throw new RuntimeException("nl2sql result is null");
}
if (nl2SQLResult.getCode() != 200) {
throw new RuntimeException("nl2sql server return error:" + nl2SQLResult.getErr_msg());
}
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 {View on GitHub (pinned to 2417e0b8b6)