Challenge - 5 Problems
Partial Prompt Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this partial prompt template rendering?
Given this Langchain partial prompt template code, what will be the final rendered prompt string?
LangChain
from langchain.prompts import PromptTemplate partial_template = PromptTemplate( input_variables=["name"], template="Hello, {name}!" ) full_template = partial_template.partial() result = full_template.format(name="Alice")
Attempts:
2 left
💡 Hint
Think about how partial templates fill in variables and then format works.
✗ Incorrect
The partial template here is created from a template with one variable 'name'. Calling partial() without arguments returns a new PromptTemplate that still expects 'name'. Formatting with name='Alice' replaces {name} with 'Alice', so the output is 'Hello, Alice!'.
📝 Syntax
intermediate2:00remaining
Which option correctly creates a partial prompt template with a fixed variable?
You want to fix the variable 'greeting' to 'Hi' in a prompt template and leave 'name' variable open. Which code snippet correctly does this?
LangChain
from langchain.prompts import PromptTemplate base_template = PromptTemplate( input_variables=["greeting", "name"], template="{greeting}, {name}!" ) # Choose the correct partial template creation:
Attempts:
2 left
💡 Hint
partial() takes keyword arguments to fix variables.
✗ Incorrect
partial() requires keyword arguments to fix variables. Option B correctly fixes 'greeting' to 'Hi'. Option B fixes 'name' instead, which is not what we want. Options C and D are invalid syntax.
❓ state_output
advanced2:00remaining
What is the output after formatting a partial prompt with multiple fixed variables?
Consider this code snippet. What is the value of 'final_prompt' after formatting?
LangChain
from langchain.prompts import PromptTemplate base = PromptTemplate( input_variables=["greeting", "name", "time"], template="{greeting}, {name}! Good {time}." ) partial1 = base.partial(greeting="Hello") partial2 = partial1.partial(time="morning") final_prompt = partial2.format(name="Bob")
Attempts:
2 left
💡 Hint
Each partial fixes one variable. Formatting replaces the remaining variable.
✗ Incorrect
First partial fixes 'greeting' to 'Hello'. Second partial fixes 'time' to 'morning'. Only 'name' remains. Formatting with name='Bob' replaces {name} with 'Bob'. So the final prompt is 'Hello, Bob! Good morning.'.
🔧 Debug
advanced2:00remaining
Why does this partial prompt template raise a KeyError?
This code raises a KeyError when formatting. What is the cause?
LangChain
from langchain.prompts import PromptTemplate base = PromptTemplate( input_variables=["greeting", "name"], template="{greeting}, {name}!" ) partial = base.partial(greeting="Hi") result = partial.format()
Attempts:
2 left
💡 Hint
Check which variables remain unfixed when calling format().
✗ Incorrect
The partial fixes 'greeting' but 'name' remains required. Calling format() without 'name' causes a KeyError because the template expects {name} but it is not provided.
🧠 Conceptual
expert2:00remaining
How does chaining partial prompt templates affect input variables?
If you chain multiple partial() calls on a PromptTemplate, how does the set of input variables change?
Attempts:
2 left
💡 Hint
Think about how fixing variables affects what remains to be filled.
✗ Incorrect
Each partial() call fixes some variables, so the new PromptTemplate returned has fewer input_variables. This means the list shrinks as variables get fixed.