Bird
0
0

Given the code below, what will be the output of final_output?

medium📝 component behavior Q13 of 15
LangChain - Prompt Templates
Given the code below, what will be the output of final_output?
prompt1 = Prompt(template="Hello, {name}!")
prompt2 = Prompt(template="How can I help you today?")
chain = Chain().add(prompt1).add(prompt2)
final_output = chain.run({"name": "Alice"})
A"Hello, Alice! How can I help you today?"
B"Hello, {name}! How can I help you today?"
C"Hello, Alice!"
DError: Missing input for prompt2
Step-by-Step Solution
Solution:
  1. Step 1: Understand prompt templates and chaining

    Prompt1 uses the variable {name} which is replaced by "Alice". Prompt2 is a fixed string without variables.
  2. Step 2: Analyze chain.run behavior

    Running the chain passes the input to prompt1, producing "Hello, Alice!" then continues to prompt2, appending "How can I help you today?".
  3. Final Answer:

    "Hello, Alice! How can I help you today?" -> Option A
  4. Quick Check:

    Chained prompts combine outputs [OK]
Quick Trick: Chained prompts concatenate outputs with variables replaced [OK]
Common Mistakes:
  • Thinking prompt2 needs input variables
  • Expecting placeholders to remain unreplaced
  • Assuming only first prompt output is returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes