0
0
LangChainframework~20 mins

Partial prompt templates in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Partial Prompt Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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")
A"Hello!"
B"Hello, {name}!"
C"Hello, Alice!"
D"{name}!"
Attempts:
2 left
💡 Hint
Think about how partial templates fill in variables and then format works.
📝 Syntax
intermediate
2: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:
Apartial = base_template.partial(name="Hi")
Bpartial = base_template.partial(greeting="Hi")
Cpartial = base_template.partial(greeting)
Dpartial = base_template.partial("Hi")
Attempts:
2 left
💡 Hint
partial() takes keyword arguments to fix variables.
state_output
advanced
2: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")
A"Hello, Bob! Good morning."
B"{greeting}, Bob! Good {time}."
C"Hello, {name}! Good morning."
D"Hello, Bob! Good {time}."
Attempts:
2 left
💡 Hint
Each partial fixes one variable. Formatting replaces the remaining variable.
🔧 Debug
advanced
2: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()
ASyntaxError due to missing colon in template
BTypeError because partial() was called without arguments
CValueError because 'greeting' is fixed twice
DKeyError because 'name' variable is missing in format() call
Attempts:
2 left
💡 Hint
Check which variables remain unfixed when calling format().
🧠 Conceptual
expert
2: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?
AEach partial() call fixes some variables, reducing the input_variables list accordingly
BPartial() calls add new variables to input_variables
CInput variables remain unchanged until the final format() call
DEach partial() call resets input_variables to the original full list
Attempts:
2 left
💡 Hint
Think about how fixing variables affects what remains to be filled.