{"record":{"id":"d946b537df8f4ab7","repo":"spring-projects/spring-ai","slug":"gemini-doesn-t-support-message-type","errorCode":null,"errorMessage":"Gemini doesn't support message type: ","messagePattern":"Gemini doesn't support 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":322,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn parts;\n\t\t}\n\t\telse if (message instanceof ToolResponseMessage toolResponseMessage) {\n\n\t\t\treturn toolResponseMessage.getResponses()\n\t\t\t\t.stream()\n\t\t\t\t.map(response -> Part.builder()\n\t\t\t\t\t.functionResponse(FunctionResponse.builder()\n\t\t\t\t\t\t.name(response.name())\n\t\t\t\t\t\t.response(parseJsonToMap(response.responseData()))\n\t\t\t\t\t\t.build())\n\t\t\t\t\t.build())\n\t\t\t\t.toList();\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException(\"Gemini doesn't support message type: \" + message.getClass());\n\t\t}\n\t}\n\n\tprivate static List<Part> mediaToParts(Collection<Media> media) {\n\t\tList<Part> parts = new ArrayList<>();\n\n\t\tList<Part> mediaParts = media.stream().map(mediaData -> {\n\t\t\tObject data = mediaData.getData();\n\t\t\tString mimeType = mediaData.getMimeType().toString();\n\n\t\t\tif (data instanceof byte[]) {\n\t\t\t\treturn Part.fromBytes((byte[]) data, mimeType);\n\t\t\t}\n\t\t\telse if (data instanceof URI || data instanceof String) {\n\t\t\t\t// Handle URI or String URLs\n\t\t\t\tString uri = data.toString();\n\t\t\t\treturn Part.fromUri(uri, mimeType);\n\t\t\t}","sourceCodeStart":304,"sourceCodeEnd":340,"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#L304-L340","documentation":"GoogleGenAiChatModel.messageToGeminiParts() handles SystemMessage, UserMessage, AssistantMessage, and ToolResponseMessage. Gemini has no representation for any other Message class, so the else branch throws this IllegalArgumentException naming the actual message class.","triggerScenarios":"Including a Message instance that is not one of the four supported types (e.g. a custom Message subclass or a legacy/deprecated message type) in the Prompt's messages list passed to call() or stream().","commonSituations":"Custom Message implementations from application code that worked with other model adapters but not the Gemini one; copied prompt-building code referencing an old message type; bridging another framework's message objects into a Spring AI Prompt without conversion.","solutions":["Convert unsupported messages to the supported types (SystemMessage/UserMessage/AssistantMessage/ToolResponseMessage) before building the Prompt.","If it is a custom Message subclass, refactor it to extend one of the standard Spring AI message classes.","Filter out unsupported message kinds from the prompt history with an explicit, logged decision instead of silently passing them."],"exampleFix":"// before\nList<Message> msgs = List.of(new MyMessage(\"hello\")); // custom type\nPrompt prompt = new Prompt(msgs);\n\n// after\nList<Message> msgs = List.of(new UserMessage(\"hello\"));\nPrompt prompt = new Prompt(msgs);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isGeminiSupported(Message m) {\n    return m instanceof SystemMessage || m instanceof UserMessage\n        || m instanceof AssistantMessage || m instanceof ToolResponseMessage;\n}","tryCatchPattern":null,"preventionTips":["Convert custom message types to standard Spring AI messages before calling the Gemini model.","Filter conversation history to supported message classes with logging.","Avoid passing third-party framework message objects directly into Prompt."],"tags":["chat","message-type","unsupported","gemini"],"backgroundTag":"unsupported-operation","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"}