{"record":{"id":"9e200a3fd3a2b7de","repo":"spring-projects/spring-ai","slug":"unknown-message-type-9e200a","errorCode":null,"errorMessage":"Unknown message type: ","messagePattern":"Unknown message type: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatModel.java","lineNumber":426,"sourceCode":"\tprivate @Nullable List<MistralAiApi.FunctionTool> calculateToolsRequestParameter(MistralAiChatOptions options,\n\t\t\tChatCompletionRequest request) {\n\t\tvar tools = ModelOptionsUtils.mergeOption(options.getTools(), request.tools());\n\t\tvar toolDefinitions = this.toolCallingManager.resolveToolDefinitions(options);\n\n\t\tif (!CollectionUtils.isEmpty(toolDefinitions)) {\n\t\t\ttools = this.getFunctionTools(toolDefinitions);\n\t\t}\n\n\t\treturn tools;\n\t}\n\n\tprivate Stream<ChatCompletionMessage> createChatCompletionMessages(Message message) {\n\t\treturn switch (message.getMessageType()) {\n\t\t\tcase USER -> Stream.of(createUserChatCompletionMessage(message));\n\t\t\tcase SYSTEM -> Stream.of(createSystemChatCompletionMessage(message));\n\t\t\tcase ASSISTANT -> Stream.of(createAssistantChatCompletionMessage(message));\n\t\t\tcase TOOL -> createToolChatCompletionMessages(message);\n\t\t\tdefault -> throw new IllegalStateException(\"Unknown message type: \" + message.getMessageType());\n\t\t};\n\t}\n\n\tprivate Stream<ChatCompletionMessage> createToolChatCompletionMessages(Message message) {\n\t\tif (message instanceof ToolResponseMessage toolResponseMessage) {\n\t\t\t// @formatter:off\n\t\t\treturn toolResponseMessage.getResponses()\n\t\t\t\t.stream()\n\t\t\t\t.map(this::createToolChatCompletionMessage);\n\t\t\t// @formatter:on\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported tool message class: \" + message.getClass().getName());\n\t\t}\n\t}\n\n\tprivate ChatCompletionMessage createToolChatCompletionMessage(ToolResponseMessage.ToolResponse toolResponse) {\n\t\treturn new ChatCompletionMessage(toolResponse.responseData(), ChatCompletionMessage.Role.TOOL,","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatModel.java#L408-L444","documentation":"MistralAiChatModel.createChatCompletionMessages(Message) switches on the Spring AI MessageType (USER, SYSTEM, ASSISTANT, TOOL) and throws IllegalStateException on any other value via the switch's default branch. In practice this only fires for custom/unknown message types.","triggerScenarios":"Passing a Message whose getMessageType() is not one of USER, SYSTEM, ASSISTANT, TOOL (e.g., a custom Message implementation) to the chat model's internal call building.","commonSituations":"Custom Message implementations with a novel MessageType used with MistralAiChatModel, or library version changes adding a MessageType not yet handled.","solutions":["Use standard Spring AI message classes (UserMessage, SystemMessage, AssistantMessage, ToolResponseMessage)","Check for library upgrades that introduced new MessageType values and update/upgrade accordingly","Filter out or map unsupported messages before calling the model"],"exampleFix":"// before\nmessages.add(new CustomMessage(\"hi\"));\n// after\nmessages.add(new UserMessage(\"hi\"));","handlingStrategy":"type-guard","validationCode":"Set<MessageType> supported = Set.of(MessageType.USER, MessageType.SYSTEM, MessageType.ASSISTANT, MessageType.TOOL);\nif (!supported.contains(msg.getMessageType())) throw new IllegalArgumentException(\"unsupported type: \" + msg.getMessageType());","typeGuard":"boolean isSupportedMessageType(Message m) {\n    return switch (m.getMessageType()) {\n        case USER, SYSTEM, ASSISTANT, TOOL -> true;\n        default -> false;\n    };\n}","tryCatchPattern":"try {\n    model.call(new Prompt(messages));\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"Unknown message type\")) {\n        logger.error(\"filter unsupported message: {}\", e.getMessage());\n    } else throw e;\n}","preventionTips":["Only use standard Spring AI message classes","Avoid custom MessageType values with MistralAiChatModel","Filter conversation history to supported message types before prompting"],"tags":["mistral","message-type","switch","unsupported"],"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"}