Bird
0
0

Given the code:

medium📝 state output Q4 of 15
LangChain - Prompt Templates
Given the code:
template = PromptTemplate(template="Hello {user}, your order {order_id} is ready.", input_variables=["user", "order_id"])
result = template.format(user="Bob", order_id=123)

What is the value of result?
AAn error occurs because order_id is a number
B"Hello Bob, your order 123 is ready."
C"Hello Bob, your order {order_id} is ready."
D"Hello {user}, your order {order_id} is ready."
Step-by-Step Solution
Solution:
  1. Step 1: Understand how format() replaces variables

    format() replaces placeholders with provided values, converting numbers to strings automatically.
  2. Step 2: Substitute variables in the template

    user="Bob" and order_id=123 replace {user} and {order_id} respectively.
  3. Final Answer:

    "Hello Bob, your order 123 is ready." -> Option B
  4. Quick Check:

    format() replaces variables with given values [OK]
Quick Trick: format() converts numbers to strings automatically [OK]
Common Mistakes:
  • Expecting placeholders to remain unchanged
  • Thinking numeric variables cause errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes