{"record":{"id":"09ad2bde5a1b5fea","repo":"spring-projects/spring-ai","slug":"unsupported-message-type-09ad2b","errorCode":null,"errorMessage":"Unsupported message type: ","messagePattern":"Unsupported message type: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/DeepSeekChatModel.java","lineNumber":385,"sourceCode":"\t\t\t\t}\n\t\t\t\tString text = assistantMessage.getText();\n\t\t\t\tAssert.state(text != null, \"text must not be null\");\n\t\t\t\treturn List.of(new ChatCompletionMessage(text, ChatCompletionMessage.Role.ASSISTANT, null, null,\n\t\t\t\t\t\ttoolCalls, isPrefixAssistantMessage, reasoningContent));\n\t\t\t}\n\t\t\telse if (message.getMessageType() == MessageType.TOOL) {\n\t\t\t\tToolResponseMessage toolMessage = (ToolResponseMessage) message;\n\n\t\t\t\ttoolMessage.getResponses()\n\t\t\t\t\t.forEach(response -> Assert.isTrue(response.id() != null, \"ToolResponseMessage must have an id\"));\n\t\t\t\treturn toolMessage.getResponses()\n\t\t\t\t\t.stream()\n\t\t\t\t\t.map(tr -> new ChatCompletionMessage(tr.responseData(), ChatCompletionMessage.Role.TOOL, tr.name(),\n\t\t\t\t\t\t\ttr.id(), null))\n\t\t\t\t\t.toList();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException(\"Unsupported message type: \" + message.getMessageType());\n\t\t\t}\n\t\t}).flatMap(List::stream).toList();\n\n\t\tChatCompletionRequest.Builder requestBuilder = ChatCompletionRequest.builder()\n\t\t\t.messages(chatCompletionMessages)\n\t\t\t.stream(stream);\n\n\t\tDeepSeekChatOptions options = (DeepSeekChatOptions) prompt.getOptions();\n\t\tAssert.state(options != null, \"requestOptions must not be null\");\n\n\t\tvalidateThinkingParameters(options);\n\n\t\tif (options.getModel() != null) {\n\t\t\trequestBuilder.model(options.getModel());\n\t\t}\n\t\tif (options.getFrequencyPenalty() != null) {\n\t\t\trequestBuilder.frequencyPenalty(options.getFrequencyPenalty());\n\t\t}","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-deepseek/src/main/java/org/springframework/ai/deepseek/DeepSeekChatModel.java#L367-L403","documentation":"DeepSeekChatModel.createRequest maps Spring AI Message objects to DeepSeek ChatCompletionMessages. It supports SYSTEM, USER, ASSISTANT, and TOOL (via tool-converted history) types; any other MessageType encountered is rejected with IllegalArgumentException naming the unsupported type.","triggerScenarios":"Building a Prompt containing a Message whose getMessageType() is not one of SYSTEM/USER/ASSISTANT/TOOL — e.g. a custom Message implementation or a message type introduced by other Spring AI modules — then calling model.call()/stream(), which routes through createRequest.","commonSituations":"Mixing messages from other model adapters into a DeepSeek prompt; custom Message subclasses; framework version drift introducing new message types not yet handled by the DeepSeek adapter.","solutions":["Only include SystemMessage, UserMessage, AssistantMessage, and ToolResponseMessage in the Prompt","Inspect the offending message type in the error text and convert it to a supported type before the call","Upgrade or patch the DeepSeek module if a newer Spring AI message type must be supported"],"exampleFix":"// before\nmessages.add(myCustomMessage); // unknown MessageType\nmodel.call(new Prompt(messages)); // throws\n// after\nmessages.add(new UserMessage(myCustomMessage.getText()));\nmodel.call(new Prompt(messages));","handlingStrategy":"validation","validationCode":"Set<MessageType> allowed = Set.of(MessageType.SYSTEM, MessageType.USER, MessageType.ASSISTANT, MessageType.TOOL);\nboolean valid = prompt.getInstructions().stream().allMatch(m -> allowed.contains(m.getMessageType()));","typeGuard":"boolean isSupportedType(Message m) { return EnumSet.of(MessageType.SYSTEM, MessageType.USER, MessageType.ASSISTANT, MessageType.TOOL).contains(m.getMessageType()); }","tryCatchPattern":"try { model.call(prompt); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Unsupported message type\")) { /* sanitize prompt messages */ } throw e; }","preventionTips":["Build DeepSeek prompts only from the four supported message types","Don't mix messages from other providers' adapters","Re-check message type handling after Spring AI upgrades"],"tags":["deepseek","message-type","illegal-argument","chat"],"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-14T05:17:10.506Z"}