Bird
0
0

You want to create a LangChain workflow that takes a list of numbers, passes it unchanged, then doubles each number. Which combination of RunnablePassthrough and RunnableLambda is correct?

hard📝 Application Q15 of 15
LangChain - Chains and LCEL
You want to create a LangChain workflow that takes a list of numbers, passes it unchanged, then doubles each number. Which combination of RunnablePassthrough and RunnableLambda is correct?
AUse RunnablePassthrough twice, no lambda needed
BUse RunnableLambda with lambda x: x, then RunnablePassthrough to double numbers
CUse RunnableLambda with lambda x: x*2, then RunnablePassthrough to pass list
DUse RunnablePassthrough to pass the list, then RunnableLambda with lambda x: [i*2 for i in x]
Step-by-Step Solution
Solution:
  1. Step 1: Pass list unchanged with RunnablePassthrough

    RunnablePassthrough returns the list as is, so it fits the first step.
  2. Step 2: Double each number with RunnableLambda

    RunnableLambda with lambda x: [i*2 for i in x] correctly doubles each element in the list.
  3. Final Answer:

    Use RunnablePassthrough to pass the list, then RunnableLambda with lambda x: [i*2 for i in x] -> Option D
  4. Quick Check:

    Passthrough passes list, lambda doubles elements = A [OK]
Quick Trick: Passthrough passes input; lambda transforms list elements [OK]
Common Mistakes:
  • Trying to double list with passthrough
  • Using lambda that multiplies list object, not elements
  • Reversing order of passthrough and lambda

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes