Bird
0
0

You want to create a prompt that greets a user and mentions their favorite color using Langchain. Which code correctly formats and injects the context for user_name = "Bob" and color = "blue"?

hard📝 Application Q15 of 15
LangChain - RAG Chain Construction
You want to create a prompt that greets a user and mentions their favorite color using Langchain. Which code correctly formats and injects the context for user_name = "Bob" and color = "blue"?
Atemplate = "Hi {user_name}, your favorite color is {color}." prompt = template.format(user_name=user_name, color=color)
Btemplate = "Hi {user}, your favorite color is {color}." prompt = template.format(user_name=user_name, color=color)
Ctemplate = "Hi {user_name}, your favorite color is {color}." prompt = template.format(user=user_name, color=color)
Dtemplate = "Hi {user_name}, your favorite color is {color}." prompt = template.fill(user_name, color)
Step-by-Step Solution
Solution:
  1. Step 1: Match placeholders with variable names

    The template uses placeholders {user_name} and {color}, so format() must use these exact names.
  2. Step 2: Check format() arguments

    template = "Hi {user_name}, your favorite color is {color}." prompt = template.format(user_name=user_name, color=color) correctly passes named arguments matching placeholders: user_name=user_name, color=color.
  3. Step 3: Eliminate incorrect options

    template = "Hi {user}, your favorite color is {color}." prompt = template.format(user_name=user_name, color=color) uses {user} placeholder mismatching the user_name= argument. template = "Hi {user_name}, your favorite color is {color}." prompt = template.format(user=user_name, color=color) mismatches placeholder and argument names. template = "Hi {user_name}, your favorite color is {color}." prompt = template.fill(user_name, color) uses non-existent fill() method.
  4. Final Answer:

    template = "Hi {user_name}, your favorite color is {color}." prompt = template.format(user_name=user_name, color=color) -> Option A
  5. Quick Check:

    Placeholder names must match format() argument names [OK]
Quick Trick: Keep placeholder and format() argument names identical [OK]
Common Mistakes:
  • Mismatching placeholder and argument names
  • Using wrong method like fill()
  • Ignoring placeholder names in template

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes