{"record":{"id":"2f604e9d6c0b76a5","repo":"spring-projects/spring-ai","slug":"image-prompt-instructions-cannot-be-empty","errorCode":null,"errorMessage":"Image prompt instructions cannot be empty","messagePattern":"Image prompt instructions cannot be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageOptions.java","lineNumber":180,"sourceCode":"\t\tif (o == null || getClass() != o.getClass()) {\n\t\t\treturn false;\n\t\t}\n\t\tOpenAiImageOptions that = (OpenAiImageOptions) o;\n\t\treturn Objects.equals(this.n, that.n) && Objects.equals(this.width, that.width)\n\t\t\t\t&& Objects.equals(this.height, that.height) && Objects.equals(this.quality, that.quality)\n\t\t\t\t&& Objects.equals(this.responseFormat, that.responseFormat) && Objects.equals(this.size, that.size)\n\t\t\t\t&& Objects.equals(this.style, that.style) && Objects.equals(this.user, that.user);\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\treturn Objects.hash(this.n, this.width, this.height, this.quality, this.responseFormat, this.size, this.style,\n\t\t\t\tthis.user);\n\t}\n\n\tpublic ImageGenerateParams toOpenAiImageGenerateParams(ImagePrompt imagePrompt) {\n\t\tif (imagePrompt.getInstructions().isEmpty()) {\n\t\t\tthrow new IllegalArgumentException(\"Image prompt instructions cannot be empty\");\n\t\t}\n\n\t\tString prompt = imagePrompt.getInstructions().get(0).getText();\n\t\tImageGenerateParams.Builder builder = ImageGenerateParams.builder().prompt(prompt);\n\n\t\t// Use deployment name if available (for Microsoft Foundry), otherwise use model\n\t\t// name\n\t\tif (this.getDeploymentName() != null) {\n\t\t\tbuilder.model(this.getDeploymentName());\n\t\t}\n\t\telse if (this.getModel() != null) {\n\t\t\tbuilder.model(this.getModel());\n\t\t}\n\n\t\tif (this.getN() != null) {\n\t\t\tbuilder.n(this.getN().longValue());\n\t\t}\n\t\tif (this.getQuality() != null) {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageOptions.java#L162-L198","documentation":"OpenAiImageOptions.toOpenAiImageGenerateParams requires the ImagePrompt to contain at least one instruction/message; an empty instructions list is rejected with this IllegalArgumentException before any API call is made.","triggerScenarios":"Calling imageModel.call(new ImagePrompt(List.of())) or building an ImagePrompt with no text messages, so imagePrompt.getInstructions().isEmpty() is true at OpenAiImageOptions.java:180.","commonSituations":"Programmatically assembling prompts from user input that arrives empty, filtering out blank messages before building the prompt, or forgetting to add any Message to the prompt list.","solutions":["Validate the prompt text is non-blank before calling the model and return a validation error to the caller.","Ensure you construct the ImagePrompt with at least one UserMessage containing text.","Trim and check user input; reject empty prompts upstream of the model call."],"exampleFix":"// before\nimageModel.call(new ImagePrompt(List.of()));\n// after\nif (prompt == null || prompt.isBlank()) {\n    throw new IllegalArgumentException(\"Image prompt text must not be empty\");\n}\nimageModel.call(new ImagePrompt(prompt));","handlingStrategy":"validation","validationCode":"if (imagePrompt == null || imagePrompt.getInstructions() == null || imagePrompt.getInstructions().isEmpty()) {\n    throw new IllegalArgumentException(\"ImagePrompt must contain at least one instruction\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return imageModel.call(imagePrompt);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"instructions cannot be empty\")) {\n        throw new EmptyPromptException(\"Provide non-empty prompt text\", e);\n    }\n    throw e;\n}","preventionTips":["Validate user-supplied prompt text before model calls","Never build ImagePrompt from unfiltered/possibly-empty message lists","Trim and check prompt text at the API boundary of your app"],"tags":["image-generation","validation","empty-input"],"backgroundTag":"empty-required-field","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}