Bird
0
0

What will be the output of this chained prompt code?

medium📝 state output Q5 of 15
LangChain - Prompt Templates
What will be the output of this chained prompt code?
from langchain import PromptTemplate, LLMChain
prompt1 = PromptTemplate(template="Name: {name}")
prompt2 = PromptTemplate(template="Greeting: Hello {name}!")
chain1 = LLMChain(prompt=prompt1)
chain2 = LLMChain(prompt=prompt2)
intermediate = chain1.run(name="Bob")
final_output = chain2.run(name=intermediate)
A"Name: Bob"
B"Greeting: Hello Bob!"
C"Greeting: Hello Name: Bob!"
DError because intermediate is not a valid name
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate intermediate output

    chain1.run returns "Name: Bob" as string.
  2. Step 2: Use intermediate as name in chain2

    chain2.run uses intermediate string as {name}, so output is "Greeting: Hello Name: Bob!".
  3. Final Answer:

    "Greeting: Hello Name: Bob!" -> Option C
  4. Quick Check:

    Output nests intermediate string as name [OK]
Quick Trick: Output of one chain can be input string for next [OK]
Common Mistakes:
  • Assuming intermediate is just 'Bob'
  • Expecting error due to nested string
  • Confusing output with original input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes