Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is RunnablePassthrough in Langchain?
RunnablePassthrough is a simple component that returns the input it receives without any changes. Think of it like a mirror that just reflects what you give it.
Click to reveal answer
beginner
How does RunnableLambda differ from RunnablePassthrough?
RunnableLambda lets you run any custom function you write on the input. Unlike RunnablePassthrough, it can change or process the input before giving back a result.
Click to reveal answer
intermediate
Show a simple example of RunnableLambda usage.
You can create a RunnableLambda that adds 1 to a number: runnable = RunnableLambda(lambda x: x + 1) runnable.invoke(5) returns 6.
Click to reveal answer
intermediate
Why use RunnablePassthrough in a chain?
RunnablePassthrough is useful when you want to pass data through a chain step without changing it. It helps keep the flow simple and clear.
Click to reveal answer
beginner
What method do you call to run the logic inside RunnableLambda or RunnablePassthrough?
You call the 'invoke' method with your input to run the logic and get the output.
Click to reveal answer
What does RunnablePassthrough do with the input it receives?
ADeletes the input
BTransforms the input using a function
CReturns the input unchanged
DSaves the input to a file
✗ Incorrect
RunnablePassthrough simply returns the input as it is without any changes.
Which Runnable lets you run a custom function on the input?
ARunnableLambda
BRunnableOutput
CRunnableChain
DRunnablePassthrough
✗ Incorrect
RunnableLambda runs any custom function you provide on the input.
How do you execute the logic inside a RunnableLambda?
Acall invoke()
Bcall execute()
Ccall run()
Dcall start()
✗ Incorrect
The 'invoke' method runs the logic inside RunnableLambda or RunnablePassthrough.
If you want to pass data through a chain without changing it, which Runnable should you use?
ARunnableModify
BRunnableLambda
CRunnableTransform
DRunnablePassthrough
✗ Incorrect
RunnablePassthrough passes data unchanged through the chain.
What is a real-life analogy for RunnablePassthrough?
AA blender mixing ingredients
BA mirror reflecting your image
CA chef cooking food
DA printer printing a document
✗ Incorrect
RunnablePassthrough acts like a mirror, returning exactly what it receives.
Explain the difference between RunnablePassthrough and RunnableLambda in Langchain.
Think about whether the input changes or not.
You got /4 concepts.
Describe a scenario where you would use RunnablePassthrough in a chain.
Imagine passing a message along without editing it.
You got /3 concepts.
Practice
(1/5)
1. What does RunnablePassthrough do with the input it receives?
easy
A. Ignores the input and returns a fixed value
B. Transforms the input using a custom function
C. Returns the input exactly as it is without any changes
D. Throws an error if input is not a string
Solution
Step 1: Understand RunnablePassthrough behavior
RunnablePassthrough is designed to return whatever input it receives without modifying it.
Step 2: Compare options with behavior
Only Returns the input exactly as it is without any changes matches this behavior exactly; others describe transformations or errors which RunnablePassthrough does not do.
Final Answer:
Returns the input exactly as it is without any changes -> Option C
Quick Check:
RunnablePassthrough returns input unchanged = A [OK]
Hint: RunnablePassthrough just passes input through unchanged [OK]
Common Mistakes:
Thinking RunnablePassthrough modifies input
Confusing RunnablePassthrough with RunnableLambda
Assuming it throws errors on certain inputs
2. Which of the following is the correct way to create a RunnableLambda that doubles a number input?
easy
A. RunnableLambda(lambda x: x + 2)
B. RunnableLambda(lambda x: x * 2)
C. RunnableLambda(lambda x: x / 2)
D. RunnableLambda(lambda x: x - 2)
Solution
Step 1: Identify the doubling function
Doubling means multiplying the input by 2, so the function should be lambda x: x * 2.
Step 2: Match with options
RunnableLambda(lambda x: x * 2) matches the doubling function exactly; others perform addition, division, or subtraction.
Final Answer:
RunnableLambda(lambda x: x * 2) -> Option B
Quick Check:
Doubling function uses multiplication by 2 = D [OK]
Hint: Doubling means multiply input by 2 in lambda [OK]
The lambda converts input to uppercase, so 'hello'.upper() returns 'HELLO'.
Final Answer:
'HELLO' -> Option A
Quick Check:
Passthrough returns input, lambda uppercases it = C [OK]
Hint: Passthrough returns input, lambda transforms it [OK]
Common Mistakes:
Expecting passthrough to modify input
Confusing case conversion result
Assuming runtime error on invoke
4. Identify the error in this code snippet:
lambda_runner = RunnableLambda(lambda x: x + 1)
result = lambda_runner.invoke('5')
print(result)
medium
A. TypeError because string '5' cannot be added to integer 1
B. SyntaxError in lambda function
C. RunnableLambda cannot be invoked with strings
D. No error; output will be '51'
Solution
Step 1: Analyze lambda operation on input
The lambda tries to add 1 to input '5', which is a string, causing a type mismatch.
Step 2: Identify error type
Adding integer 1 to string '5' raises a TypeError in Python.
Final Answer:
TypeError because string '5' cannot be added to integer 1 -> Option A
Quick Check:
Adding int to string causes TypeError = B [OK]
Hint: Adding int to string causes TypeError in Python [OK]
Common Mistakes:
Assuming implicit string to int conversion
Thinking output is string concatenation
Confusing error types
5. 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
A. Use RunnablePassthrough twice, no lambda needed
B. Use RunnableLambda with lambda x: x, then RunnablePassthrough to double numbers
C. Use RunnableLambda with lambda x: x*2, then RunnablePassthrough to pass list
D. Use RunnablePassthrough to pass the list, then RunnableLambda with lambda x: [i*2 for i in x]
Solution
Step 1: Pass list unchanged with RunnablePassthrough
RunnablePassthrough returns the list as is, so it fits the first step.
Step 2: Double each number with RunnableLambda
RunnableLambda with lambda x: [i*2 for i in x] correctly doubles each element in the list.
Final Answer:
Use RunnablePassthrough to pass the list, then RunnableLambda with lambda x: [i*2 for i in x] -> Option D
Quick Check:
Passthrough passes list, lambda doubles elements = A [OK]
Hint: Passthrough passes input; lambda transforms list elements [OK]
Common Mistakes:
Trying to double list with passthrough
Using lambda that multiplies list object, not elements