Bird
0
0

Which code snippet correctly initializes a Langchain prompt template with a placeholder called user?

easy📝 Syntax Q3 of 15
LangChain - Prompt Templates
Which code snippet correctly initializes a Langchain prompt template with a placeholder called user?
Atemplate = PromptTemplate(template="Hello, {user}!") output = template.format(username="Alice")
Btemplate = PromptTemplate(template="Hello, {user}!")
Ctemplate = PromptTemplate(template="Hello, {username}!") output = template.format(user="Alice")
Dtemplate = PromptTemplate(template="Hello, user!")
Step-by-Step Solution
Solution:
  1. Step 1: Understand PromptTemplate initialization

    The template string must include the placeholder name inside curly braces exactly as the input variable.
  2. Step 2: Check placeholder and input variable consistency

    template = PromptTemplate(template="Hello, {user}!") correctly defines the template with {user} and does not show formatting errors.
  3. Final Answer:

    template = PromptTemplate(template="Hello, {user}!") -> Option B
  4. Quick Check:

    Placeholder matches variable name [OK]
Quick Trick: Placeholder names must match exactly in template and format [OK]
Common Mistakes:
  • Using different variable names in template and format
  • Omitting curly braces around placeholders
  • Not specifying input variables when required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes