Bird
0
0

Identify the error in this LangChain code snippet:

medium📝 Debug Q6 of 15
LangChain - Fundamentals
Identify the error in this LangChain code snippet:
from langchain.prompts import PromptTemplate
prompt = PromptTemplate(template='Hello {name}', input_variables='name')
Atemplate should be a function, not a string.
Binput_variables should be a list, not a string.
CPromptTemplate does not exist in langchain.prompts.
DMissing import for OpenAI.
Step-by-Step Solution
Solution:
  1. Step 1: Check PromptTemplate parameters

    input_variables must be a list of strings, not a single string.
  2. Step 2: Identify the error

    Passing 'name' as a string causes a type error; it should be ['name'].
  3. Final Answer:

    input_variables should be a list, not a string. -> Option B
  4. Quick Check:

    input_variables must be ['name'] [OK]
Quick Trick: input_variables must be a list even if one item [OK]
Common Mistakes:
  • Passing a string instead of list for input_variables
  • Thinking template must be a function
  • Confusing import errors with parameter errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes