{"record":{"id":"a0f3b1525f479804","repo":"mem0ai/mem0","slug":"model-must-be-an-instance-of-basechatmodel","errorCode":null,"errorMessage":"`model` must be an instance of BaseChatModel","messagePattern":"`model` must be an instance of BaseChatModel","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/llms/langchain.py","lineNumber":21,"sourceCode":"from mem0.configs.llms.base import BaseLlmConfig\nfrom mem0.llms.base import LLMBase\n\ntry:\n    from langchain.chat_models.base import BaseChatModel\n    from langchain_core.messages import AIMessage\nexcept ImportError:\n    raise ImportError(\"langchain is not installed. Please install it using `pip install langchain`\")\n\n\nclass LangchainLLM(LLMBase):\n    def __init__(self, config: Optional[BaseLlmConfig] = None):\n        super().__init__(config)\n\n        if self.config.model is None:\n            raise ValueError(\"`model` parameter is required\")\n\n        if not isinstance(self.config.model, BaseChatModel):\n            raise ValueError(\"`model` must be an instance of BaseChatModel\")\n\n        self.langchain_model = self.config.model\n\n    def _parse_response(self, response: AIMessage, tools: Optional[List[Dict]]):\n        \"\"\"\n        Process the response based on whether tools are used or not.\n\n        Args:\n            response: AI Message.\n            tools: The list of tools provided in the request.\n\n        Returns:\n            str or dict: The processed response.\n        \"\"\"\n        if not tools:\n            return response.content\n\n        processed_response = {","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/llms/langchain.py#L3-L39","documentation":"Error \"`model` must be an instance of BaseChatModel\" thrown in mem0ai/mem0.","triggerScenarios":"Thrown at mem0/llms/langchain.py:21 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a Langchain BaseChatModel instance, not an arbitrary object, in the 'model' field."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}