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 placeholder that is not listed in input_variables.
Mismatching the placeholder name and input variable.
✗ Incorrect
The variable placeholder in the template must match the input variable name, which is 'name' here.
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 variable name not defined in the template.
Passing the value without specifying the variable name.
✗ Incorrect
The format method requires the variable name 'name' to replace the placeholder in the template.
3fill in blank
hardFix the error in the code by choosing the correct input variable name for the template.
LangChain
prompt = PromptTemplate(template="Your favorite color is [1].", input_variables=["color"])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using British spelling 'colour' instead of 'color'.
Using camelCase or different variable names.
✗ Incorrect
The placeholder and input variable must match exactly; 'color' is correct here.
4fill in blank
hardFill both blanks to create a prompt template with two variables and format it correctly.
LangChain
prompt = PromptTemplate(template="Hello, [1]! You are [2] years old.", input_variables=["name", "age"]) formatted = prompt.format([1]="Bob", [2]=30)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names between template and format method.
Using variables not declared in input_variables.
✗ Incorrect
The placeholders and input variables must match: 'name' and 'age' are correct.
5fill in blank
hardFill all three blanks to create a reusable prompt template with three variables and format it with values.
LangChain
prompt = PromptTemplate(template="Dear [1], your order [2] will arrive on [3].", input_variables=["customer", "order_id", "delivery_date"]) message = prompt.format([1]="Anna", [2]="12345", [3]="Monday")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names not declared in input_variables.
Mismatching placeholder names and format keys.
✗ Incorrect
The placeholders and input variables must match exactly: 'customer', 'order_id', and 'delivery_date'.