Bird
0
0

Given this code snippet:

medium📝 component behavior Q13 of 15
LangChain - Prompt Templates
Given this code snippet:
from langchain.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_template('Hi {user}! How can I help you today?')
message = prompt.format_prompt(user='Alice').to_messages()
print(message[0].content)

What will be printed?
AHi {user}! How can I help you today?
BHi Alice! How can I help you today?
CHi ! How can I help you today?
DError: format_prompt missing argument
Step-by-Step Solution
Solution:
  1. Step 1: Understand placeholder replacement

    The placeholder {user} is replaced by the value 'Alice' passed to format_prompt.
  2. Step 2: Check printed message content

    message[0].content contains the formatted string with 'Alice' inserted.
  3. Final Answer:

    Hi Alice! How can I help you today? -> Option B
  4. Quick Check:

    Placeholder replaced with 'Alice' in output [OK]
Quick Trick: format_prompt replaces placeholders with given values [OK]
Common Mistakes:
  • Thinking placeholders remain unreplaced in output
  • Assuming missing argument error without passing user
  • Confusing message object with string directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes