{"record":{"id":"a46321569437f5d2","repo":"alibaba/nacos","slug":"prompt-is-required-a46321","errorCode":null,"errorMessage":"Prompt is required","messagePattern":"Prompt is required","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"copilot/src/main/java/com/alibaba/nacos/copilot/form/PromptOptimizationForm.java","lineNumber":44,"sourceCode":"public class PromptOptimizationForm {\n    \n    /**\n     * Original Prompt content (required).\n     */\n    private String prompt;\n    \n    /**\n     * Optimization goal/requirement description (optional).\n     * e.g., \"Make response more concise\", \"Add more examples\", \"Support multi-language\"\n     */\n    private String optimizationGoal;\n    \n    /**\n     * Validate form data.\n     */\n    public void validate() {\n        if (StringUtils.isBlank(prompt)) {\n            throw new IllegalArgumentException(\"Prompt is required\");\n        }\n    }\n    \n    public String getPrompt() {\n        return prompt;\n    }\n    \n    public void setPrompt(String prompt) {\n        this.prompt = prompt;\n    }\n    \n    public String getOptimizationGoal() {\n        return optimizationGoal;\n    }\n    \n    public void setOptimizationGoal(String optimizationGoal) {\n        this.optimizationGoal = optimizationGoal;\n    }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/copilot/src/main/java/com/alibaba/nacos/copilot/form/PromptOptimizationForm.java#L26-L62","documentation":"Thrown by PromptOptimizationForm.validate() (copilot module) when the `prompt` field is null, empty, or whitespace-only. This form backs the POST /v3/console/copilot/prompt/optimize SSE endpoint. The original prompt is mandatory because the AI needs source material to optimize; optimizationGoal is optional.","triggerScenarios":"Posting to /v3/console/copilot/prompt/optimize with an empty/whitespace/null `prompt` field. The front-end handlers guard `if (!template.trim()) return;` but direct API callers can send an empty prompt.","commonSituations":"User clears the template then clicks optimize. Programmatic call with an empty prompt body. Template variable resolving to empty.","solutions":["Send a non-blank `prompt` string in the request body.","Keep the client-side trim guard and replicate it for any API client.","If the prompt comes from a variable, ensure it resolves to non-empty content."],"exampleFix":"// before\nbody: JSON.stringify({ prompt: template, optimizationGoal: optimizeGoal })\n\n// after\nif (!template.trim()) {\n  setOptimizeError('Prompt template is empty');\n  return;\n}\nbody: JSON.stringify({ prompt: template, optimizationGoal: optimizeGoal })","handlingStrategy":"validation","validationCode":"function hasPrompt(prompt: unknown): boolean {\n  return typeof prompt === 'string' && prompt.trim().length > 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Include a non-blank prompt in the optimize request body.","Keep the client-side template.trim() guard and replicate it for API clients.","Validate that template variables resolve to non-empty content."],"tags":["copilot","prompt-optimize","java","validation","form"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}