Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a prompt template with a variable placeholder.
LangChain
from langchain import PromptTemplate prompt = PromptTemplate(template="Hello, [1]!", input_variables=["name"])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name in input_variables that does not match the placeholder.
Forgetting to include the variable in input_variables list.
✗ Incorrect
The input variable name must match the placeholder in the template exactly, so 'name' is correct.
2fill in blank
mediumComplete the code to format the prompt with the variable 'name' set to 'Alice'.
LangChain
formatted_prompt = prompt.format([1]="Alice")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than defined in the template.
Passing the variable as a positional argument instead of keyword.
✗ Incorrect
The format method requires the variable name matching the input_variables, which is 'name'.
3fill in blank
hardFix the error in the code to inject context into the prompt template.
LangChain
context = "You are a helpful assistant." prompt = PromptTemplate(template="Context: [1]\nQuestion: {question}", input_variables=["context", "question"])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a placeholder that is not in input_variables.
Mixing curly braces syntax for placeholders.
✗ Incorrect
The placeholder must match an input variable; here 'context' is correct to inject the context string.
4fill in blank
hardFill both blanks to create a prompt template that includes context and question variables.
LangChain
prompt = PromptTemplate(template="Context: [1]\nQuestion: [2]", input_variables=["context", "question"])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the variable names in placeholders.
Using variable names not listed in input_variables.
✗ Incorrect
The placeholders must match the input_variables 'context' and 'question' respectively.
5fill in blank
hardFill all three blanks to format the prompt with context and question values.
LangChain
formatted = prompt.format([1]="You are a bot.", [2]="What is AI?", [3]="ignored")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names not defined in the prompt template.
Passing positional arguments instead of keyword arguments.
✗ Incorrect
The format method keys must match input_variables; 'context' and 'question' are used, 'extra' is an extra variable.