{"record":{"id":"2323eee885cf5c68","repo":"alibaba/nacos","slug":"parameter-missing-2323ee","errorCode":"PARAMETER_MISSING","errorMessage":"promptKey is required","messagePattern":"promptKey is required","errorType":"validation","errorClass":"NacosApiException","httpStatus":400,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java","lineNumber":135,"sourceCode":"    \n    @Autowired(required = false)\n    public void setAiResourceIndexMaintenanceService(\n        AiResourceIndexMaintenanceService resourceIndexMaintenanceService) {\n        if (resourceIndexMaintenanceService != null) {\n            this.resourceIndexMaintenanceService = resourceIndexMaintenanceService;\n        }\n    }\n    \n    // ========== Admin APIs ==========\n    \n    @Override\n    public String createDraft(String namespaceId, String promptKey, String basedOnVersion,\n        String targetVersion,\n        String template, List<PromptVariable> variables, String commitMsg, String description,\n        String bizTags)\n        throws NacosException {\n        if (StringUtils.isBlank(promptKey)) {\n            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,\n                \"promptKey is required\");\n        }\n        \n        AiResource meta = resourceManager.findMeta(namespaceId, promptKey, RESOURCE_TYPE_PROMPT);\n        \n        if (meta == null) {\n            // Brand-new prompt: require template\n            if (StringUtils.isBlank(template)) {\n                throw new NacosApiException(NacosException.INVALID_PARAM,\n                    ErrorCode.PARAMETER_MISSING,\n                    \"template is required when creating a new prompt\");\n            }\n            String version =\n                StringUtils.isBlank(targetVersion) ? DEFAULT_INITIAL_VERSION : targetVersion;\n            validateVersion(version);\n            \n            String storageJson = writePromptToStorage(namespaceId, promptKey, version, template,\n                variables, null);","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java#L117-L153","documentation":"Thrown by PromptOperationServiceImpl.createDraft (admin path) when promptKey is blank. promptKey is the primary identifier for creating/publishing a prompt draft. Reported as PARAMETER_MISSING (HTTP 400).","triggerScenarios":"POST create-prompt-draft with promptKey omitted, null, or whitespace-only.","commonSituations":"Form submission where the key field is empty; API client that did not set the key; automated script missing the key argument.","solutions":["Supply a non-blank promptKey in the createDraft request.","Validate the key client-side before the call.","Generate a deterministic key (e.g. slugified name) if the user did not provide one."],"exampleFix":"// before\npromptService.createDraft(ns, null, ...); // 400\n// after\nString key = StringUtils.defaultIfBlank(promptKey, slugify(name));\npromptService.createDraft(ns, key, ...);","handlingStrategy":"validation","validationCode":"// Ensure promptKey is present before creating a draft\nif (promptKey == null || promptKey.isBlank()) {\n    throw new IllegalArgumentException(\"promptKey is required\");\n}\npromptService.createDraft(ns, promptKey, basedOn, target, template, vars, msg, desc, tags);","typeGuard":null,"tryCatchPattern":"try {\n    promptService.createDraft(ns, key, basedOn, target, template, vars, msg, desc, tags);\n} catch (NacosApiException e) {\n    if (e.getErrCode() == ErrorCode.PARAMETER_MISSING.getCode()\n        && e.getErrMsg().contains(\"promptKey\")) {\n        // require the user to provide a key\n    } else { throw e; }\n}","preventionTips":["Mark promptKey @NotBlank on the request form/model.","Auto-derive a key from the prompt name when the user omits it.","Validate required fields in the controller before delegating."],"tags":["prompt","parameter-missing","validation","create","admin","nacos-ai"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}