Bird
0
0

What is wrong with this LangChain code?

medium📝 Debug Q7 of 15
LangChain - Fundamentals
What is wrong with this LangChain code?
from langchain.chains import LLMChain
from langchain.llms import OpenAI
llm = OpenAI()
prompt = 'Hello {name}'
chain = LLMChain(llm=llm, prompt=prompt)
ALLMChain does not accept prompt parameter.
Bllm must be a string, not an OpenAI object.
CMissing parentheses when creating OpenAI instance.
Dprompt should be a PromptTemplate, not a string.
Step-by-Step Solution
Solution:
  1. Step 1: Check LLMChain prompt parameter

    LLMChain expects prompt to be a PromptTemplate object, not a plain string.
  2. Step 2: Identify the error

    Passing a string causes a type error; prompt must be wrapped in PromptTemplate.
  3. Final Answer:

    prompt should be a PromptTemplate, not a string. -> Option D
  4. Quick Check:

    LLMChain requires PromptTemplate [OK]
Quick Trick: Wrap prompt strings in PromptTemplate for LLMChain [OK]
Common Mistakes:
  • Passing raw string as prompt
  • Confusing llm parameter type
  • Ignoring required object types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes