Concept Flow - RunnablePassthrough and RunnableLambda
Input Data
Pass input as-is
Output same as input
Next step or result
RunnablePassthrough sends input through unchanged. RunnableLambda applies a function to input and outputs the result.
passthrough = RunnablePassthrough() lambda_run = RunnableLambda(lambda x: x * 2) output1 = passthrough.invoke(5) output2 = lambda_run.invoke(5)
| Step | Runnable Type | Input | Action | Output |
|---|---|---|---|---|
| 1 | RunnablePassthrough | 5 | Pass input as-is | 5 |
| 2 | RunnableLambda | 5 | Apply lambda x*2 | 10 |
| 3 | RunnablePassthrough | Hello | Pass input as-is | Hello |
| 4 | RunnableLambda | Hello | Apply lambda x*2 (string repeat) | HelloHello |
| 5 | End | - | - | - |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|---|---|
| passthrough | RunnablePassthrough instance | Same instance | Same instance | Same instance | Same instance | Same instance |
| lambda_run | RunnableLambda instance with lambda x*2 | Same instance | Same instance | Same instance | Same instance | Same instance |
| output1 | None | 5 | 5 | 5 | 5 | 5 |
| output2 | None | None | 10 | 10 | 10 | 10 |
RunnablePassthrough: returns input unchanged. RunnableLambda: applies a function to input and returns result. Use invoke(input) to run. RunnableLambda needs a function compatible with input type. Useful for chaining operations in LangChain.