Bird
0
0

What is wrong with this LangChain code snippet?

medium📝 Debug Q14 of 15
LangChain - Fundamentals
What is wrong with this LangChain code snippet?
from langchain import PromptTemplate, LLMChain
from langchain.llms import OpenAI

prompt = PromptTemplate(template="Hello {name}!")
llm = OpenAI(temperature=0)
chain = LLMChain(llm=llm, prompt=prompt)

result = chain.run(person="Bob")
print(result)
AThe placeholder name in the prompt does not match the argument name in run()
BOpenAI class cannot be instantiated with temperature=0
CPromptTemplate requires a 'variables' argument
DLLMChain requires a 'memory' argument
Step-by-Step Solution
Solution:
  1. Step 1: Check placeholder and run() argument names

    The prompt expects 'name' but run() is called with 'person', causing a missing variable error.
  2. Step 2: Verify other code parts

    Temperature=0 is valid, 'variables' is optional, and 'memory' is not required.
  3. Final Answer:

    The placeholder name in the prompt does not match the argument name in run() -> Option A
  4. Quick Check:

    Placeholder and argument names must match = A [OK]
Quick Trick: Match placeholder names exactly with run() arguments [OK]
Common Mistakes:
  • Assuming temperature=0 is invalid
  • Thinking 'variables' argument is mandatory
  • Believing 'memory' is required for LLMChain

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes