{"record":{"id":"ad9e45a46dc9fd88","repo":"alibaba/nacos","slug":"prompt-key-cannot-be-blank","errorCode":null,"errorMessage":"Prompt key cannot be blank","messagePattern":"Prompt key cannot be blank","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/ai/model/prompt/PromptUtils.java","lineNumber":57,"sourceCode":"     */\n    public static final String PROMPT_MAIN_DATA_ID = \"content.json\";\n    \n    private static final String DOUBLE_UNDERSCORE = \"__\";\n    \n    private PromptUtils() {\n    }\n    \n    /**\n     * Build the Nacos Config group for a specific prompt version.\n     *\n     * @param promptKey prompt key (name)\n     * @param version   version string, e.g. \"1.0.0\"\n     * @return config group string, e.g. \"prompt__{enc_promptKey}__{enc_version}\"\n     * @throws IllegalArgumentException if promptKey or version is blank\n     */\n    public static String buildPromptVersionGroup(String promptKey, String version) {\n        if (StringUtils.isBlank(promptKey)) {\n            throw new IllegalArgumentException(\"Prompt key cannot be blank\");\n        }\n        if (StringUtils.isBlank(version)) {\n            throw new IllegalArgumentException(\"Version cannot be blank\");\n        }\n        return PROMPT_GROUP_PREFIX + NacosAiConfigKeyCodec.encodeVersionedGroupSegment(promptKey)\n            + DOUBLE_UNDERSCORE + NacosAiConfigKeyCodec.encodeVersionedGroupSegment(version);\n    }\n}\n","sourceCodeStart":39,"sourceCodeEnd":66,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/ai/model/prompt/PromptUtils.java#L39-L66","documentation":"PromptUtils.buildPromptVersionGroup throws IllegalArgumentException when promptKey is blank (null, empty, or whitespace-only). The method builds a Nacos Config group string of the form 'prompt__{enc_key}__{enc_version}' and cannot proceed without a valid key.","triggerScenarios":"Calling buildPromptVersionGroup with a null or empty promptKey. Happens when the key comes from unvalidated user input, a missing JSON field, or a null map entry.","commonSituations":"API request omits the promptKey field. A batch job processes prompt records and encounters one with a missing key. A variable was declared but never assigned before being passed.","solutions":["Validate promptKey is non-blank before calling buildPromptVersionGroup.","Add an early-return or domain error at the controller/service layer for blank keys.","Use StringUtils.hasText() or StringUtils.isBlank() as a guard."],"exampleFix":"// before\nString group = PromptUtils.buildPromptVersionGroup(\"\", \"1.0.0\"); // throws\n\n// after\nif (!StringUtils.hasText(promptKey)) {\n    throw new IllegalArgumentException(\"promptKey is required\");\n}\nString group = PromptUtils.buildPromptVersionGroup(promptKey, \"1.0.0\");","handlingStrategy":"validation","validationCode":"if (StringUtils.isBlank(promptKey)) {\n    throw new IllegalArgumentException(\"promptKey is required\");\n}","typeGuard":"public static boolean isPromptKeyValid(String key) {\n    return key != null && !key.trim().isEmpty();\n}","tryCatchPattern":"try {\n    group = PromptUtils.buildPromptVersionGroup(promptKey, version);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Prompt key cannot be blank\")) {\n        return badRequest(\"promptKey is required\");\n    }\n    throw e;\n}","preventionTips":["Validate promptKey at the API boundary before calling group builders.","Reject blank keys early to avoid deep stack traces.","Use StringUtils.isBlank() for consistent checks."],"tags":["prompt","validation","blank","config-group"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}