{"record":{"id":"97dd451e514dcc00","repo":"langchain-ai/langchain","slug":"unsupported-message-type-type-message","errorCode":null,"errorMessage":"Unsupported message type: {type(message)}","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/chat.py","lineNumber":1489,"sourceCode":"                message_type_str, template, template_format=template_format\n            )\n        elif (\n            hasattr(message_type_str, \"model_fields\")\n            and \"type\" in message_type_str.model_fields\n        ):\n            message_type = message_type_str.model_fields[\"type\"].default\n            message_ = _create_template_from_message_type(\n                message_type, template, template_format=template_format\n            )\n        else:\n            message_ = message_type_str(\n                prompt=PromptTemplate.from_template(\n                    cast(\"str\", template), template_format=template_format\n                )\n            )\n    else:\n        msg = f\"Unsupported message type: {type(message)}\"  # type: ignore[unreachable]\n        raise NotImplementedError(msg)\n\n    return message_\n\n\n# For backwards compat:\n_convert_to_message = _convert_to_message_template\n","sourceCodeStart":1471,"sourceCodeEnd":1496,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/chat.py#L1471-L1496","documentation":"NotImplementedError raised in _convert_to_message_template when a message passed to from_messages is not one of the supported types: Base(BaseChat)Message(Base)PromptTemplate, BaseMessage, str, tuple, or dict. This is the catch-all for unsupported input shapes.","triggerScenarios":"`from_messages([42])`, `from_messages([None])`, `from_messages([b\"bytes message\"])`, or passing a generator/iterable of messages as a single element rather than unpacking it.","commonSituations":"Passing bytes, None, or a number because a variable was never rendered; passing a nested list [[...]] instead of splatting; custom objects that aren't message subclasses.","solutions":["Check `type(message)` in the error output and convert the item to str/tuple/dict/BaseMessage.","Flatten nested lists: from_messages([*inner]) instead of from_messages([inner]).","Guard dynamic pipelines by asserting each item is str/tuple/dict/BaseMessage before building the prompt."],"exampleFix":"# before\nChatPromptTemplate.from_messages([[(\"human\", \"hi\")]])\n\n# after\nChatPromptTemplate.from_messages([(\"human\", \"hi\")])","handlingStrategy":"type-guard","validationCode":"from langchain_core.messages import BaseMessage\n\ndef supported_message(m):\n    return isinstance(m, (str, tuple, dict, BaseMessage))","typeGuard":"from langchain_core.messages import BaseMessage\nfrom typing import Any\n\ndef is_message_like(m: Any) -> bool:\n    return isinstance(m, (str, tuple, dict, BaseMessage))","tryCatchPattern":"try:\n    prompt = ChatPromptTemplate.from_messages(messages)\nexcept NotImplementedError as e:\n    raise ValueError(f\"Unsupported message shape in list: {e}\") from e","preventionTips":["Flatten nested lists of messages before passing to from_messages.","Validate each element is str/tuple/dict/BaseMessage in dynamic prompt builders.","Add type hints (list[MessageLikeRepresentation]) so mypy catches bad element types early."],"tags":["prompts","from-messages","type-validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}