alibaba/nacos · error · NacosApiException

10000

10000

Error message

template is required when creating a new prompt

What it means

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.

Source

Thrown at ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java:144

    // ========== Admin APIs ==========
    
    @Override
    public String createDraft(String namespaceId, String promptKey, String basedOnVersion,
        String targetVersion,
        String template, List<PromptVariable> variables, String commitMsg, String description,
        String bizTags)
        throws NacosException {
        if (StringUtils.isBlank(promptKey)) {
            throw new NacosApiException(NacosException.INVALID_PARAM, ErrorCode.PARAMETER_MISSING,
                "promptKey is required");
        }
        
        AiResource meta = resourceManager.findMeta(namespaceId, promptKey, RESOURCE_TYPE_PROMPT);
        
        if (meta == null) {
            // Brand-new prompt: require template
            if (StringUtils.isBlank(template)) {
                throw new NacosApiException(NacosException.INVALID_PARAM,
                    ErrorCode.PARAMETER_MISSING,
                    "template is required when creating a new prompt");
            }
            String version =
                StringUtils.isBlank(targetVersion) ? DEFAULT_INITIAL_VERSION : targetVersion;
            validateVersion(version);
            
            String storageJson = writePromptToStorage(namespaceId, promptKey, version, template,
                variables, null);
            
            String currentUser = VisibilityHelper.resolveCurrentIdentity();
            resourceManager.insertVersionRow(namespaceId, promptKey, RESOURCE_TYPE_PROMPT,
                StringUtils.isBlank(currentUser) ? DEFAULT_AUTHOR : currentUser,
                VERSION_STATUS_DRAFT, version, commitMsg, storageJson);
            
            resourceManager.initOrUpdateMetaForDraft(namespaceId, promptKey, RESOURCE_TYPE_PROMPT,
                description, bizTags, version, null, true);
            AiResourceTraceService.logSuccess(RESOURCE_TYPE_PROMPT, promptKey, version,

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Provide a non-empty template string when creating a new prompt.
  2. If you have no template yet, create the prompt via a different flow or supply a placeholder template and update later via updateDraft.
  3. Pre-validate that template is non-blank before the create call when meta does not exist.

Example fix

// before
promptService.createDraft(ns, "greeting", null, null, null, null, ...); // 400 new prompt
// after
promptService.createDraft(ns, "greeting", null, null, "Hello, {{name}}!", vars, ...);
Defensive patterns

Strategy: validation

Validate before calling

// For a brand-new prompt, require a template
AiResource meta = promptService.findMeta(ns, promptKey);
if (meta == null && (template == null || template.isBlank())) {
    throw new IllegalArgumentException("template is required for a new prompt");
}
promptService.createDraft(ns, promptKey, basedOn, target, template, vars, msg, desc, tags);

Try / catch

try {
    promptService.createDraft(ns, key, basedOn, target, template, vars, msg, desc, tags);
} catch (NacosApiException e) {
    if (e.getErrCode() == ErrorCode.PARAMETER_MISSING.getCode()
        && e.getErrMsg().contains("template is required when creating")) {
        // prompt user for template content, then retry
    } else { throw e; }
}

Prevention

When it happens

Trigger: First-time prompt creation with template omitted/null/whitespace while the promptKey does not yet exist.

Common situations: 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).

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/58651e706ebd3e48. Report an issue: GitHub.