Bird
0
0

What is wrong with this Langchain prompt template code?

medium📝 Debug Q14 of 15
LangChain - Prompt Templates
What is wrong with this Langchain prompt template code?
from langchain import PromptTemplate

template = PromptTemplate(template="Welcome, {user}!")
output = template.format(username="Bob")
print(output)
AThe placeholder name in template and format do not match
BThe template string is missing curly braces
CThe format method is not supported in PromptTemplate
DThe import statement is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Compare placeholder and format argument names

    The template uses {user} but the format call uses username="Bob" which does not match.
  2. Step 2: Understand placeholder replacement rules

    Since the placeholder {user} is not provided a value, formatting will fail or leave it unchanged.
  3. Final Answer:

    The placeholder name in template and format do not match -> Option A
  4. Quick Check:

    Placeholder and argument names must match = A [OK]
Quick Trick: Match placeholder names exactly in format() call [OK]
Common Mistakes:
  • Using different names for placeholders and values
  • Forgetting curly braces in template
  • Assuming format() is unsupported

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes