from langchain.chains import LLMChain # Legacy chain class
Error:
ImportError: cannot import name 'LLMChain' from
'langchain.chains'

from langchain.chains import LLMChain # Legacy chain class
Error:
ImportError: cannot import name 'LLMChain' from
'langchain.chains'
Fix (Use LCEL in v0.2+):
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
prompt = ChatPromptTemplate.from_template("Tell me a joke about {topic}")
model = ChatOpenAI()
chain = prompt | model # ✅ LCEL replace LLMChain
Tell us about your project and get help tailored to your problem.
Contact usEveryone can read. Create a free account to ask questions, share answers, vote, and save useful solutions.