{"record":{"id":"58651e706ebd3e48","repo":"alibaba/nacos","slug":"10000-58651e","errorCode":"10000","errorMessage":"template is required when creating a new prompt","messagePattern":"template is required when creating a new prompt","errorType":"exception","errorClass":"NacosApiException","httpStatus":400,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java","lineNumber":144,"sourceCode":"    // ========== 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);\n            \n            String currentUser = VisibilityHelper.resolveCurrentIdentity();\n            resourceManager.insertVersionRow(namespaceId, promptKey, RESOURCE_TYPE_PROMPT,\n                StringUtils.isBlank(currentUser) ? DEFAULT_AUTHOR : currentUser,\n                VERSION_STATUS_DRAFT, version, commitMsg, storageJson);\n            \n            resourceManager.initOrUpdateMetaForDraft(namespaceId, promptKey, RESOURCE_TYPE_PROMPT,\n                description, bizTags, version, null, true);\n            AiResourceTraceService.logSuccess(RESOURCE_TYPE_PROMPT, promptKey, version,","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java#L126-L162","documentation":"Thrown by PromptOperationServiceImpl.createDraft when creating a brand-new prompt (no existing metadata) but the template parameter is blank. A new prompt must have initial template content; you cannot create an empty prompt draft. Reported as PARAMETER_MISSING (HTTP 400). Note: the code listing shows code=10000 which is the PARAMETER_MISSING numeric code.","triggerScenarios":"First-time prompt creation with template omitted/null/whitespace while the promptKey does not yet exist.","commonSituations":"UI 'create' action submitted before the user entered template text; API call that only sets metadata but not the template; assuming the server auto-generates a template (it does not for prompts, unlike AgentSpec which allows empty drafts).","solutions":["Provide a non-empty template string when creating a new prompt.","If you have no template yet, create the prompt via a different flow or supply a placeholder template and update later via updateDraft.","Pre-validate that template is non-blank before the create call when meta does not exist."],"exampleFix":"// before\npromptService.createDraft(ns, \"greeting\", null, null, null, null, ...); // 400 new prompt\n// after\npromptService.createDraft(ns, \"greeting\", null, null, \"Hello, {{name}}!\", vars, ...);","handlingStrategy":"validation","validationCode":"// For a brand-new prompt, require a template\nAiResource meta = promptService.findMeta(ns, promptKey);\nif (meta == null && (template == null || template.isBlank())) {\n    throw new IllegalArgumentException(\"template is required for a new prompt\");\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(\"template is required when creating\")) {\n        // prompt user for template content, then retry\n    } else { throw e; }\n}","preventionTips":["Distinguish create-new vs fork flows in the UI and require template only for new.","Provide a default/placeholder template to satisfy the constraint.","Validate template presence client-side when the prompt does not yet exist."],"tags":["prompt","parameter-missing","validation","create","template","nacos-ai"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}