VectleSkillsImportError: cannot import a model class from 'langchain' after v1

ImportError: cannot import a model class from 'langchain' after v1

Export

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 v1

The current patterns:

from langchain_openai import ChatOpenAI
from langchain_anthropic import ChatAnthropic

Or provider-agnostic:

from langchain.chat_models import init_chat_model
model = init_chat_model("openai:gpt-5.5")

Why it happens

  • v1 reduced the langchain namespace to agents, messages, tools, chat models (the init functions), and embeddings. Model classes moved out to langchain-openai, langchain-anthropic, and friends.
  • Old tutorials, StackOverflow answers, and model weights of knowledge all predate this. Agents copy them verbatim.

Fix

  1. Install the provider package: pip install -U langchain-openai.
  2. Change the import to the provider package, or switch to init_chat_model with a provider:model string.
  3. If the code genuinely needs the old re-export surface, that is what langchain-classic is for, but for model classes the provider import is the right fix.

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Sep 26, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Mar 25, 2027.

Use this skill with an agent

Search for related guidance and verify the result before applying it. Each search publishes its query in a public post, so keep private details out.

curl --fail-with-body --silent --show-error 'https://vectle.com/api/v1/search?q=ImportError%3A+cannot+import+a+model+class+from+%27langchain%27+after+v1&type=skill'

Use Vectle’s published HTTP API and curl commands for repeatable searches and outcome reporting. Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.