diff --git a/libs/vertexai/langchain_google_vertexai/chat_models.py b/libs/vertexai/langchain_google_vertexai/chat_models.py index 17777517..401506ca 100644 --- a/libs/vertexai/langchain_google_vertexai/chat_models.py +++ b/libs/vertexai/langchain_google_vertexai/chat_models.py @@ -303,13 +303,12 @@ def _convert_to_parts(message: BaseMessage) -> List[Part]: pass except ValueError: pass - # A linting error is thrown here because it does not think this line is - # reachable due to typing, but mypy is wrong so we ignore the lint - # error. - if isinstance(raw_content, int): # type: ignore - raw_content = str(raw_content) # type: ignore - if isinstance(raw_content, str): - raw_content = [raw_content] + if isinstance(raw_content, (int, float, str)): + raw_content = [str(raw_content)] + elif isinstance(raw_content, list): + raw_content = [str(item) for item in raw_content] + else: + raise TypeError(f"Unsupported type: {type(raw_content)}") result = [] for raw_part in raw_content: part = _convert_to_prompt(raw_part)