Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
LangChain - Prompt Templates
Identify the error in this code snippet:
template = PromptTemplate(template="Welcome {name}!", input_variables=["name"])
result = template.format("Alice")
APromptTemplate requires a model parameter.
Binput_variables should be a dictionary, not a list.
CTemplate string must use $name instead of {name}.
Dformat() is called without keyword arguments.
Step-by-Step Solution
Solution:
  1. Step 1: Check how format() is called

    format() requires variables passed as keyword arguments like name="value".
  2. Step 2: Identify the error

    Calling format("Alice") passes a positional argument, causing a TypeError.
  3. Final Answer:

    format() is called without keyword arguments. -> Option D
  4. Quick Check:

    format() needs keyword arguments for variables [OK]
Quick Trick: Use keyword arguments in format(), e.g., format(name='Bob') [OK]
Common Mistakes:
  • Passing variables positionally to format()
  • Confusing input_variables type
  • Thinking model parameter is mandatory here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes