Challenge - 5 Problems
PromptTemplate Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this PromptTemplate render?
Given the PromptTemplate below, what will be the rendered output when input variable 'name' is 'Alice'?
LangChain
from langchain.prompts import PromptTemplate template = "Hello, {name}! Welcome to LangChain." prompt = PromptTemplate(template=template, input_variables=["name"]) output = prompt.format(name="Alice") print(output)
Attempts:
2 left
💡 Hint
Look at how the variable 'name' is used inside curly braces and how format replaces it.
✗ Incorrect
The PromptTemplate replaces {name} with the value passed in format, which is 'Alice'. So the output is 'Hello, Alice! Welcome to LangChain.'.
📝 Syntax
intermediate2:00remaining
Which option correctly creates a PromptTemplate with two input variables?
You want to create a PromptTemplate with variables 'city' and 'weather'. Which code snippet is correct?
Attempts:
2 left
💡 Hint
input_variables must be a list of strings.
✗ Incorrect
input_variables expects a list of strings naming the variables used in the template. Option B correctly uses a list of strings.
❓ state_output
advanced2:00remaining
What is the output of this PromptTemplate with missing variable?
What happens when you try to format a PromptTemplate but omit one required variable?
LangChain
from langchain.prompts import PromptTemplate template = "Today in {city}, the temperature is {temp} degrees." prompt = PromptTemplate(template=template, input_variables=["city", "temp"]) output = prompt.format(city="Paris") print(output)
Attempts:
2 left
💡 Hint
Check what happens if a required variable is not provided to format.
✗ Incorrect
PromptTemplate.format requires all variables listed in input_variables. Omitting 'temp' causes a KeyError.
🧠 Conceptual
advanced2:00remaining
Which statement about PromptTemplate input_variables is true?
Choose the correct statement about the input_variables parameter in PromptTemplate.
Attempts:
2 left
💡 Hint
Think about how PromptTemplate validates variables.
✗ Incorrect
input_variables must exactly list all variables used in the template. Omitting or adding extra variables causes errors.
🔧 Debug
expert2:00remaining
Why does this PromptTemplate raise a ValueError?
Examine the code and choose the reason for the ValueError.
LangChain
from langchain.prompts import PromptTemplate template = "Hello, {name}! Your age is {age}." prompt = PromptTemplate(template=template, input_variables=["name", "age", "location"]) output = prompt.format(name="Bob", age=30, location="NY") print(output)
Attempts:
2 left
💡 Hint
Check if input_variables matches variables in the template exactly.
✗ Incorrect
PromptTemplate raises ValueError if input_variables list contains variables not present in the template string.