{"record":{"id":"b4a115f4dbc7b3ae","repo":"spring-projects/spring-ai","slug":"unsupported-message-type-s","errorCode":null,"errorMessage":"Unsupported message type: %s","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/Prompt.java","lineNumber":216,"sourceCode":"\t\tList<Message> messagesCopy = new ArrayList<>();\n\t\tthis.messages.forEach(message -> {\n\t\t\tif (message instanceof UserMessage userMessage) {\n\t\t\t\tmessagesCopy.add(userMessage.copy());\n\t\t\t}\n\t\t\telse if (message instanceof SystemMessage systemMessage) {\n\t\t\t\tmessagesCopy.add(systemMessage.copy());\n\t\t\t}\n\t\t\telse if (message instanceof AssistantMessage assistantMessage) {\n\t\t\t\tmessagesCopy.add(assistantMessage.copy());\n\t\t\t}\n\t\t\telse if (message instanceof ToolResponseMessage toolResponseMessage) {\n\t\t\t\tmessagesCopy.add(ToolResponseMessage.builder()\n\t\t\t\t\t.responses(new ArrayList<>(toolResponseMessage.getResponses()))\n\t\t\t\t\t.metadata(new HashMap<>(toolResponseMessage.getMetadata()))\n\t\t\t\t\t.build());\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException(\"Unsupported message type: \" + message.getClass().getName());\n\t\t\t}\n\t\t});\n\n\t\treturn messagesCopy;\n\t}\n\n\t/**\n\t * Augments the first system message in the prompt with the provided function. If no\n\t * system message is found, a new one is created with the provided text.\n\t * @return a new {@link Prompt} instance with the augmented system message.\n\t */\n\tpublic Prompt augmentSystemMessage(Function<SystemMessage, SystemMessage> systemMessageAugmenter) {\n\t\tvar messagesCopy = new ArrayList<>(this.messages);\n\t\tboolean found = false;\n\t\tfor (int i = 0; i < messagesCopy.size(); i++) {\n\t\t\tMessage message = messagesCopy.get(i);\n\t\t\tif (message instanceof SystemMessage systemMessage) {\n\t\t\t\tmessagesCopy.set(i, systemMessageAugmenter.apply(systemMessage));","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/Prompt.java#L198-L234","documentation":"Prompt.instructionsCopy() deep-copies the message list but only knows UserMessage, AssistantMessage, SystemMessage and ToolResponseMessage. Any other Message implementation passed into a Prompt triggers this IllegalArgumentException, because PromptTemplate/Prompt cannot safely copy an unknown message type.","triggerScenarios":"Building a Prompt with a custom Message implementation (or a null/unexpected type in the list) and then calling copy() or builder(), which invokes instructionsCopy().","commonSituations":"Custom Message classes from older Spring AI versions or third-party integrations after an upgrade that added ToolResponseMessage handling; passing MockMessage-style test doubles.","solutions":["Use only supported Message types: SystemMessage, UserMessage, AssistantMessage, ToolResponseMessage.","Implement your custom message by extending AssistantMessage/UserMessage so it matches an accepted branch.","Serialize the custom message's content into a standard UserMessage before constructing the Prompt."],"exampleFix":"// before\nPrompt p = new Prompt(List.of(new MyCustomMessage(\"hi\")));\n// after\nPrompt p = new Prompt(List.of(new UserMessage(\"hi\")));","handlingStrategy":"validation","validationCode":"List.of(\"SystemMessage\",\"UserMessage\",\"AssistantMessage\",\"ToolResponseMessage\").contains(msg.getClass().getSimpleName());","typeGuard":"boolean isSupportedMessage(Message m) { return m instanceof SystemMessage || m instanceof UserMessage || m instanceof AssistantMessage || m instanceof ToolResponseMessage; }","tryCatchPattern":"try { Prompt copy = prompt.copy(); } catch (IllegalArgumentException e) { logger.error(\"unsupported message type in prompt\", e); }","preventionTips":["Only pass built-in Spring AI Message types into Prompt","Map custom message types to UserMessage/AssistantMessage before building a Prompt","After upgrading Spring AI, re-check custom Message implementations against the supported set"],"tags":["prompt","message-type","illegal-argument"],"backgroundTag":"unsupported-enum-value","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}