0
0
LangChainframework~10 mins

Why templates create reusable prompts in LangChain - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aage
Bname
Clocation
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Using a placeholder that is not listed in input_variables.
Mismatching the placeholder name and input variable.
2fill in blank
medium

Complete 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'
Aname
Bage
Clocation
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the template.
Passing the value without specifying the variable name.
3fill in blank
hard

Fix 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'
Acolour
BfavColor
Cfavorite_color
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Using British spelling 'colour' instead of 'color'.
Using camelCase or different variable names.
4fill in blank
hard

Fill 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'
Aname
Bage
Cusername
Dyears
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names between template and format method.
Using variables not declared in input_variables.
5fill in blank
hard

Fill 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'
Acustomer
Border_id
Cdelivery_date
Darrival_time
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names not declared in input_variables.
Mismatching placeholder names and format keys.