Bird
0
0

Given the following code, what will be the output of full_prompt.format(name="Alice")?

medium📝 component behavior Q13 of 15
LangChain - Prompt Templates
Given the following code, what will be the output of full_prompt.format(name="Alice")?
from langchain.prompts import PartialPromptTemplate, PromptTemplate
partial = PartialPromptTemplate(template="Hello {name}", input_variables=["name"])
full_prompt = PromptTemplate(template="{greeting}, welcome!", input_variables=["greeting"])
full_prompt = full_prompt.partial(greeting=partial)
A"{greeting}, welcome!"
B"Hello Alice, welcome!"
C"Hello {name}, welcome!"
DError: missing variable 'name'
Step-by-Step Solution
Solution:
  1. Step 1: Understand partial prompt substitution

    The partial prompt replaces the greeting variable in full_prompt with the partial template.
  2. Step 2: Format the full prompt with name="Alice"

    Calling full_prompt.format(name="Alice") fills {name} in partial, producing "Hello Alice", then inserts it into full prompt, resulting in "Hello Alice, welcome!".
  3. Final Answer:

    "Hello Alice, welcome!" -> Option B
  4. Quick Check:

    Partial fills greeting, then full prompt formats [OK]
Quick Trick: Partial fills variables inside main prompt [OK]
Common Mistakes:
  • Expecting raw template string without substitution
  • Confusing variable names and placeholders
  • Missing that partial is nested inside full prompt

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes