{"record":{"id":"addbdbaf752ceef1","repo":"jd-opensource/joyagent-jdgenie","slug":"nl2sql-server-return-error","errorCode":null,"errorMessage":"nl2sql server return error:","messagePattern":"nl2sql server return error:","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java","lineNumber":101,"sourceCode":"                .map(code -> Pattern.compile(\"(?i)(?<!`)\\\\b\" + Pattern.quote(code) + \"\\\\b(?!`)\"))\n                .toList();\n\n        Matcher matcher;\n        for (Pattern pattern : patterns) {\n            matcher = pattern.matcher(input);\n            if (matcher.find()) {\n                return matcher.replaceFirst(\"`$0`\");\n            }\n        }\n        return input;\n    }\n\n    private List<ChatQueryData> nl2sqlQueryData(NL2SQLReq request, NL2SQLResult nl2SQLResult) throws Exception {\n        if (nl2SQLResult == null || nl2SQLResult.getCode() == null) {\n            throw new RuntimeException(\"nl2sql result is null\");\n        }\n        if (nl2SQLResult.getCode() != 200) {\n            throw new RuntimeException(\"nl2sql server return error:\" + nl2SQLResult.getErr_msg());\n        }\n        if (CollectionUtils.isEmpty(nl2SQLResult.getData())) {\n            throw new RuntimeException(\"nl2sql返回为空\");\n        }\n        nl2SQLResult.setRootQuery(request.getQuery());\n        for (NL2SQLResult.NL2SQLData nl2SQLData : nl2SQLResult.getData()) {\n            String prettySql = replaceFirstMatchedOrThrow(nl2SQLData.getNl2sql(), request.getModelCodeList());\n            nl2SQLData.setNl2sql(prettySql);\n        }\n        return queryData(request, nl2SQLResult);\n    }\n\n    public String getTableName(ChatModelInfoDto modelInfo) {\n        if (\"table\".equalsIgnoreCase(modelInfo.getType())) {\n            return modelInfo.getContent();\n        } else if (\"sql\".equalsIgnoreCase(modelInfo.getType())) {\n            return \"(\" + modelInfo.getContent() + \") t\";\n        } else {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java#L83-L119","documentation":"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.","triggerScenarios":"Agent responds with valid JSON whose code != 200 (e.g. 500 on SQL generation failure, 4xx on bad request params like query/model codes).","commonSituations":"Malformed or too-complex natural language query; agent-side LLM/DB failure; schema metadata missing so the agent cannot generate SQL.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return nl2sqlQueryData(request, result);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"nl2sql server return error:\")) {\n        String agentErrMsg = e.getMessage().substring(\"nl2sql server return error:\".length());\n        log.error(\"agent error: {}\", agentErrMsg);\n    }\n    throw e;\n}","preventionTips":["Surface err_msg to callers so root cause is visible","Validate query/model inputs before sending to agent","Monitor agent non-200 rates"],"tags":["nl2sql","api-error","upstream"],"backgroundTag":"api-error-response","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}