Bird
0
0

Given the code below, what will be the output of print(results)?

medium📝 component behavior Q13 of 15
LangChain - Evaluation and Testing
Given the code below, what will be the output of print(results)?
from langchain import PromptTemplate
prompt1 = PromptTemplate(template='Hello {name}')
prompt2 = PromptTemplate(template='Hi {name}')
inputs = {'name': 'Alice'}
results = [prompt1.format(**inputs), prompt2.format(**inputs)]
print(results)
A['Hello Alice', 'Hi Alice']
B['Hello {name}', 'Hi {name}']
C['Hello', 'Hi']
DError: format method not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand PromptTemplate.format()

    The format method replaces placeholders like {name} with values from inputs.
  2. Step 2: Apply inputs to both prompts

    Both prompts get 'Alice' for {name}, so outputs are 'Hello Alice' and 'Hi Alice'.
  3. Final Answer:

    ['Hello Alice', 'Hi Alice'] -> Option A
  4. Quick Check:

    format() replaces placeholders correctly [OK]
Quick Trick: format() fills placeholders with input values [OK]
Common Mistakes:
MISTAKES
  • Thinking format() returns template string unchanged
  • Expecting placeholders to remain in output
  • Assuming format() method does not exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes