Bird
0
0

Given the code snippet:

medium📝 component behavior Q4 of 15
LangChain - Prompt Templates
Given the code snippet:
from langchain import PromptTemplate

template = PromptTemplate(template="Hello {user}", input_variables=["user"])
prompt = template.format(user="Alice")
print(prompt)

What will be printed?
AHello {user}
BHello Alice
CHello user
DError: Missing variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand the template and input variables

    The template has a placeholder {user} and input_variables list includes "user".
  2. Step 2: Analyze the format method call

    The format method replaces {user} with the string "Alice".
  3. Final Answer:

    Hello Alice -> Option B
  4. Quick Check:

    Placeholder replaced by input = B [OK]
Quick Trick: format() replaces placeholders with given values [OK]
Common Mistakes:
  • Printing the template string without replacement
  • Confusing placeholder name with literal text
  • Expecting an error when variable is provided

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes