快速结论:这个报错通常出现在用户直接复制运行 langchain-core 文档字符串里的 `Example:` 代码时,示例里 from langchain_core.chat_models import ... 指向了一个并不存在的模块。优先排查是否照抄了旧示例中的导入路径,并改用 langchain_openai / langchain_anthropic 中的对应类。
适用环境:Issue 已确认环境为 Windows 10.0.26200、Python 3.12.10、langchain_core 1.6.4、langchain 1.4.2、langchain_openai 1.6.6、langsmith 0.8.18;问题针对 langchain-core,检查基线为 master 7622d3dce。
最快修复方案:把示例导入改为确实存在的包,例如从 langchain_openai 导入 ChatOpenAI、从 langchain_anthropic 导入 Anthropic 对应类,不要从 langchain_core.chat_models 或 langchain_core.chat_models.openai / langchain_core.chat_models.anthropic 导入。Issue 中作者提出并计划提交的修复仅改文档字符串,不改变代码或默认值。
注意事项:该修复属于文档清理,尚未在 Issue 中确认已合入;openai: 前缀只被 init_chat_model 识别,传给 ChatOpenAI 时会原样发送,因此复制示例时要一并去掉前缀。旧 Claude 模型 ID 的问题来自示例本身,不代表用户代码逻辑错误。
问题场景
用户在 LangChain 中直接复制 langchain-core 文档字符串里的 Example: 代码运行,涉及的类包括 FewShotChatMessagePromptTemplate(prompts/few_shot.py)、RunnableRetry(runnables/retry.py)、RunnableWithFallbacks(runnables/fallbacks.py)、StrOutputParser(output_parsers/string.py)、trim_messages(messages/utils.py)、RunnableWithMessageHistory(runnables/history.py)、InMemoryRateLimiter 以及 Runnable.configurable_alternatives。复制后的导入或模型名不符合当前实际可用接口,从而触发导入报错或请求异常。
报错原文
No module named 'langchain_core.chat_models'
No module named 'langchain_core.chat_models'
No module named 'langchain_core.chat_models'
openai:gpt-5.5
原因分析
最可能的原因是 langchain-core 文档字符串示例未随代码演进而更新,具体分三类:
- 导入了不存在的模块
langchain_core.chat_models(以及langchain_core.chat_models.openai、langchain_core.chat_models.anthropic); - 把只属于
init_chat_model的openai:模型前缀直接传给了ChatOpenAI,后者会把openai:gpt-5.5原样作为模型名发往 API; - 示例中使用了已退役或旧版 Anthropic 模型 ID,包括
claude-2、claude-3-haiku-20240307、claude-sonnet-4-5-20250929、claude-sonnet-4-6。
Issue 作者提出的修复方向为:改从 langchain_openai / langchain_anthropic 导入,去掉 openai: 前缀,并使用 Anthropic 当前 GA ID;该修复仅涉及文档字符串。
环境排查
- 确认当前
langchain-core版本,Issue 中为 1.6.4; - 确认
langchain1.4.2、langchain-openai1.6.6、langsmith0.8.18; - 确认 Python 版本,Issue 中为 3.12.10;
- 确认操作系统,Issue 中为 Windows 10.0.26200;
- 检查示例代码中是否存在
langchain_core.chat_models系列导入; - 检查传给
ChatOpenAI的model参数是否带openai:前缀; - 检查示例中使用的 Anthropic 模型 ID 是否仍为当前可用版本。
解决步骤
- 将
from langchain_core.chat_models import ...改为从实际安装的集成包导入,例如从langchain_openai导入ChatOpenAI,从langchain_anthropic导入 Anthropic 对话模型类。 - 如果示例用于
init_chat_model,可保留provider:model前缀;如果直接实例化ChatOpenAI,去掉前缀,把"openai:gpt-5.5"改为纯模型名。 - 将示例中的旧 Anthropic 模型 ID 替换为当前 GA ID;Issue 作者提到使用
claude-sonnet-5、claude-haiku-4-5,可优先尝试,但需以 Anthropic 官方模型列表为准。 - 注意
configurable_alternatives示例在 master 5704d9d48 上仍使用claude-sonnet-4-5-20250929,Issue 讨论中认为该处仍需更新。 - 若你是在自己的项目中遇到相同报错,不要修改 langchain-core 源码,直接在调用侧按上述方式改正导入与模型名。
验证方法
重新运行修正后的示例,确认不再出现 No module named 'langchain_core.chat_models';对 ChatOpenAI 调用 _get_request_payload("hello")["model"],确认返回的是纯模型名而不是 openai:gpt-5.5;如果发起了真实 API 请求,确认目标模型 ID 被服务端接受、不再因退役模型报错。
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。
![[Bug]: pytorch rocm 6.0 with 7600xt = HSA_STATUS_ERROR_INVALID_ISA](https://www.chat-gpts.plus/wp-content/uploads/2026/09/15434-1e9b08ba-768x403.jpg)

