{"record":{"id":"49a8c29a2bf51599","repo":"jd-opensource/joyagent-jdgenie","slug":"nl2sql-49a8c2","errorCode":null,"errorMessage":"nl2sql返回为空","messagePattern":"nl2sql返回为空","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java","lineNumber":104,"sourceCode":"        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 {\n            throw new RuntimeException(\"不支持的模型类型\" + modelInfo.getType());\n        }\n    }","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/service/Nl2SqlService.java#L86-L122","documentation":"Guard in Nl2SqlService.nl2sqlQueryData: before converting the NL2SQL service response into chat query data, the code verifies the response envelope exists and carries a code. A null result or null code means the upstream NL2SQL call produced no usable response object (transport failure, empty reply, deserialization gap). Both runNL2SQLSync and runNL2SQLSse funnel through here, so any caller of those entry points can surface this RuntimeException when the NL2SQL backend fails to return a well-formed response.","triggerScenarios":"NL2SQLResult.getCode()==200 and getData() is null or empty after a successful sync/SSE run.","commonSituations":"Query too vague so the agent generated nothing; model/table has no matching data; agent version returning results under a different JSON field so data deserializes empty.","solutions":["Verify the request query and selected models can actually produce SQL","Log the full nl2SQLResult JSON to check the agent truly returned no data vs a field-name mismatch","Tighten the prompt/query or choose models with proper schema metadata"],"exampleFix":"// before\nif (CollectionUtils.isEmpty(nl2SQLResult.getData())) {\n    throw new RuntimeException(\"nl2sql返回为空\");\n}\n// after\nif (CollectionUtils.isEmpty(nl2SQLResult.getData())) {\n    throw new RuntimeException(\"nl2sql返回为空, query=\" + request.getQuery());\n}","handlingStrategy":"validation","validationCode":"// after receiving result\nif (result.getCode() == 200 && CollectionUtils.isEmpty(result.getData())) {\n    log.warn(\"agent returned empty data for query: {}\", request.getQuery());\n}","typeGuard":null,"tryCatchPattern":"try {\n    return nl2sqlQueryData(request, result);\n} catch (RuntimeException e) {\n    if (\"nl2sql返回为空\".equals(e.getMessage())) {\n        // degrade gracefully: return empty dataset instead of failing\n        return Collections.emptyList();\n    }\n    throw e;\n}","preventionTips":["Ensure selected models have schema metadata the agent can use","Log full result JSON to distinguish true-empty from field-name mismatch","Keep agent/backend response schema in sync"],"tags":["nl2sql","empty-result","api"],"backgroundTag":"empty-result-set","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"}