Bird
0
0

What is wrong with this chaining code snippet?

medium📝 Debug Q7 of 15
LangChain - Prompt Templates
What is wrong with this chaining code snippet?
from langchain import PromptTemplate, LLMChain
prompt1 = PromptTemplate(template="{greeting}, {name}!")
chain = LLMChain(prompt=prompt1)
output = chain.run(greeting="Hi")
print(output)
AMissing 'name' variable causes runtime error
BPromptTemplate template syntax is invalid
CLLMChain requires two prompts to chain
Drun() method does not accept keyword arguments
Step-by-Step Solution
Solution:
  1. Step 1: Check variables in template

    Template requires 'greeting' and 'name' variables.
  2. Step 2: Analyze run() call

    Only 'greeting' is provided; 'name' is missing, causing error.
  3. Final Answer:

    Missing 'name' variable causes runtime error -> Option A
  4. Quick Check:

    All template variables must be passed to run() [OK]
Quick Trick: Pass all template variables to avoid errors [OK]
Common Mistakes:
  • Assuming partial variables are enough
  • Thinking template syntax is wrong
  • Believing run() disallows keyword args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes