Bird
0
0

You want to create a Langchain prompt that includes a list of tasks dynamically. Which approach correctly injects the list tasks = ['Translate', 'Summarize'] into the prompt template?

hard📝 Application Q8 of 15
LangChain - RAG Chain Construction
You want to create a Langchain prompt that includes a list of tasks dynamically. Which approach correctly injects the list tasks = ['Translate', 'Summarize'] into the prompt template?
Atemplate = "Tasks: {tasks}" prompt = template.format(tasks=tasks[0])
Btemplate = "Tasks: {tasks}" prompt = template.format(tasks=', '.join(tasks))
Ctemplate = "Tasks: {tasks}" prompt = template.format(tasks=str(tasks))
Dtemplate = "Tasks: {tasks}" prompt = template.format(tasks=tasks)
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to format lists in strings

    Directly injecting a list shows brackets and quotes, which is not user-friendly.
  2. Step 2: Use join to create a readable string

    Joining list elements with ', ' creates a clean string for the prompt.
  3. Final Answer:

    template = "Tasks: {tasks}" prompt = template.format(tasks=', '.join(tasks)) -> Option B
  4. Quick Check:

    Join list elements for readable injection [OK]
Quick Trick: Join list items into string before injecting [OK]
Common Mistakes:
  • Injecting list object directly causing ugly output
  • Using str() which includes brackets and quotes
  • Injecting only first list item unintentionally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes