{"record":{"id":"40b1bed4817733a4","repo":"spring-projects/spring-ai","slug":"unsupported-message-type-40b1be","errorCode":null,"errorMessage":"Unsupported message type: ","messagePattern":"Unsupported message type: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/GoogleGenAiChatModel.java","lineNumber":237,"sourceCode":"\t\tthis.cachedContentService = (genAiClient != null && genAiClient.caches != null && genAiClient.async != null\n\t\t\t\t&& genAiClient.async.caches != null) ? new GoogleGenAiCachedContentService(genAiClient) : null;\n\n\t\tif (toolCallingManager instanceof GoogleGenAiToolCallingManager) {\n\t\t\tthis.toolCallingManager = toolCallingManager;\n\t\t}\n\t\telse {\n\t\t\tthis.toolCallingManager = new GoogleGenAiToolCallingManager(toolCallingManager);\n\t\t}\n\t}\n\n\tprivate static GeminiMessageType toGeminiMessageType(MessageType type) {\n\n\t\tAssert.notNull(type, \"Message type must not be null\");\n\n\t\treturn switch (type) {\n\t\t\tcase SYSTEM, USER, TOOL -> GeminiMessageType.USER;\n\t\t\tcase ASSISTANT -> GeminiMessageType.MODEL;\n\t\t\tdefault -> throw new IllegalArgumentException(\"Unsupported message type: \" + type);\n\t\t};\n\t}\n\n\tList<Part> messageToGeminiParts(Message message) {\n\n\t\tif (message instanceof SystemMessage systemMessage) {\n\n\t\t\tList<Part> parts = new ArrayList<>();\n\n\t\t\tif (systemMessage.getText() != null) {\n\t\t\t\tparts.add(Part.fromText(systemMessage.getText()));\n\t\t\t}\n\n\t\t\treturn parts;\n\t\t}\n\t\telse if (message instanceof UserMessage userMessage) {\n\t\t\tList<Part> parts = new ArrayList<>();\n\t\t\tif (userMessage.getText() != null) {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/GoogleGenAiChatModel.java#L219-L255","documentation":"GoogleGenAiChatModel.toGeminiMessageType() maps Spring AI MessageType values to Gemini roles: SYSTEM, USER, and TOOL map to USER; ASSISTANT maps to MODEL. Any other/unknown MessageType has no Gemini equivalent, so the switch default throws this IllegalArgumentException.","triggerScenarios":"Passing a Message whose getMessageType() returns a custom or unrecognized MessageType (not SYSTEM, USER, ASSISTANT, or TOOL) into the chat model's contents() conversion path — typically via a custom Message implementation.","commonSituations":"Custom Message subclasses returning a bespoke MessageType enum value; version drift where a new MessageType was added in Spring AI but this model's switch wasn't updated; routing a function-result message type through the wrong channel.","solutions":["Use only standard message types: SystemMessage, UserMessage, AssistantMessage, or ToolResponseMessage.","Fix custom Message implementations to return one of the supported MessageType values.","Align Spring AI versions so the chat model supports all MessageType values present in your classpath."],"exampleFix":"// before\nMessage msg = new MyCustomMessage(\"hi\", MessageType.FUNCTION);\n\n// after\nMessage msg = new UserMessage(\"hi\");","handlingStrategy":"type-guard","validationCode":"if (!(type == MessageType.SYSTEM || type == MessageType.USER || type == MessageType.ASSISTANT || type == MessageType.TOOL)) {\n    throw new IllegalArgumentException(\"MessageType not supported by Gemini: \" + type);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only build prompts from standard Spring AI message classes.","Audit custom Message implementations for non-standard MessageType values.","Keep Spring AI core and model adapter versions aligned."],"tags":["chat","message-type","unsupported","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-14T05:17:10.506Z"}