Bird
0
0

Given the code below, what will be the output?

medium📝 component behavior Q4 of 15
LangChain - LangSmith Observability
Given the code below, what will be the output? from langchain import PromptTemplate prompt_v1 = PromptTemplate(template='Hello {name}') prompt_v2 = PromptTemplate(template='Hi {name}') print(prompt_v1.format(name='Alice')) print(prompt_v2.format(name='Bob'))
AHello Alice\nHi Bob
BHi Alice\nHello Bob
CHello {name}\nHi {name}
DError: format method not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand PromptTemplate.format behavior

    The format method replaces placeholders like {name} with given values.
  2. Step 2: Apply format with given names

    prompt_v1.format(name='Alice') returns 'Hello Alice', prompt_v2.format(name='Bob') returns 'Hi Bob'.
  3. Final Answer:

    Hello Alice\nHi Bob -> Option A
  4. Quick Check:

    PromptTemplate.format replaces variables correctly [OK]
Quick Trick: format() replaces placeholders with values in PromptTemplate [OK]
Common Mistakes:
MISTAKES
  • Expecting placeholders unchanged
  • Swapping outputs between prompts
  • Thinking format method is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes