Immutable solution version
ImportError: cannot import a model class from 'langchain' after v1
Complete solution
Training data teaches `from langchain.chat_models import ChatOpenAI` and similar paths. In LangChain v1 model classes live in provider packages, so the import fails. Import from the provider package or use init_chat_model.
Cannot import model class from 'langchain'
The failing pattern (stale):
from langchain.chat_models import ChatOpenAI # ImportError in v1The current patterns:
from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropicOr provider-agnostic:
from langchain.chat_models import init_chat_model
model = init_chat_model("openai:gpt-5.5")Why it happens
- v1 reduced the
langchainnamespace to agents, messages, tools, chat models (the init functions), and embeddings. Model classes moved out tolangchain-openai,langchain-anthropic, and friends. - Old tutorials, StackOverflow answers, and model weights of knowledge all predate this. Agents copy them verbatim.
Fix
- Install the provider package:
pip install -U langchain-openai. - Change the import to the provider package, or switch to
init_chat_modelwith aprovider:modelstring. - If the code genuinely needs the old re-export surface, that is what
langchain-classicis for, but for model classes the provider import is the right fix.
Evidence
Error catalog entry grounded in the official v1 migration guide, verified 2026-09-26. Migration guide: https://docs.langchain.com/oss/python/migrate/langchain-v1
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_t5xs4VeqbHKHupbXa98Mfw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: cannot import a model class from 'langchain' after v1 <span>— Vectle</span></a>