Challenge - 5 Problems
LangChain Prompt Version Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What output does this LangChain prompt version comparison produce?
Given two prompt versions in LangChain, what will be the printed output when comparing their templates?
LangChain
from langchain.prompts import PromptTemplate prompt_v1 = PromptTemplate(template="Hello, {name}!") prompt_v2 = PromptTemplate(template="Hello, {name}! How are you?") print(prompt_v1.template == prompt_v2.template) print(prompt_v1.format(name="Alice")) print(prompt_v2.format(name="Alice"))
Attempts:
2 left
💡 Hint
Check if the template strings are exactly the same and how format replaces placeholders.
✗ Incorrect
The two prompt templates have different template strings, so comparing them returns False. Formatting replaces {name} with 'Alice' in each template, producing different outputs.
📝 Syntax
intermediate2:00remaining
Which prompt version code snippet will raise a KeyError?
Identify which LangChain prompt version code will cause a KeyError when formatting.
Attempts:
2 left
💡 Hint
Check if the placeholder name matches the format argument name.
✗ Incorrect
Option D uses a template with {username} but calls format with user="Bob", causing a KeyError because 'username' is missing.
❓ state_output
advanced2:00remaining
What is the output of comparing two PromptTemplate objects with identical templates but different input variables?
Consider these two prompt versions. What will be the result of comparing their templates and input variables?
LangChain
from langchain.prompts import PromptTemplate prompt1 = PromptTemplate(template="Hi {name}, your age is {age}.", input_variables=["name", "age"]) prompt2 = PromptTemplate(template="Hi {name}, your age is {age}.", input_variables=["name"]) print(prompt1.template == prompt2.template) print(prompt1.input_variables == prompt2.input_variables)
Attempts:
2 left
💡 Hint
Templates are strings; input_variables are lists. Compare both separately.
✗ Incorrect
The template strings are identical, so the first comparison is True. The input_variables lists differ, so the second comparison is False.
🔧 Debug
advanced2:00remaining
Why does this prompt version comparison raise a TypeError?
Examine the code and identify why comparing prompt_v1 and prompt_v2 raises a TypeError.
LangChain
from langchain.prompts import PromptTemplate prompt_v1 = PromptTemplate(template="Hello {name}") prompt_v2 = "Hello {name}" print(prompt_v1 == prompt_v2)
Attempts:
2 left
💡 Hint
Check the types of the objects being compared and how LangChain defines equality.
✗ Incorrect
LangChain's PromptTemplate does not support equality comparison with strings, so comparing prompt_v1 (PromptTemplate) with prompt_v2 (string) raises a TypeError.
🧠 Conceptual
expert2:00remaining
Which statement best describes the difference between prompt versions in LangChain?
Select the most accurate description of how prompt versions differ and how LangChain manages them.
Attempts:
2 left
💡 Hint
Consider what aspects define a prompt version and how LangChain handles PromptTemplate objects.
✗ Incorrect
LangChain's PromptTemplate instances differ by template, input variables, and partial variables. LangChain does not provide built-in version control or automatic merging; each instance is independent.