RunnablePassthrough Class — langchain Architecture
Architecture documentation for the RunnablePassthrough class in passthrough.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 8e2a3559_7880_8305_e0df_ce67ee25f95f["RunnablePassthrough"] 74fd3998_c4d9_f441_95fd_4c9845487771["passthrough.py"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|defined in| 74fd3998_c4d9_f441_95fd_4c9845487771 0357b4e6_848b_edac_cbd6_9d569cd10648["__repr_args__()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 0357b4e6_848b_edac_cbd6_9d569cd10648 3edeb018_7b8a_9aeb_cdad_ed682c82c11a["__init__()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 3edeb018_7b8a_9aeb_cdad_ed682c82c11a d2a19a55_0807_7e69_c1c0_1cb6dc4b8174["is_lc_serializable()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| d2a19a55_0807_7e69_c1c0_1cb6dc4b8174 7ae1fda0_7feb_ed22_fb4b_45ad18cd9b75["get_lc_namespace()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 7ae1fda0_7feb_ed22_fb4b_45ad18cd9b75 ad1103a7_6f87_21fc_703f_278be83873ab["InputType()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| ad1103a7_6f87_21fc_703f_278be83873ab 7596fc7b_caec_4e32_ee51_3bdba644e3dd["OutputType()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 7596fc7b_caec_4e32_ee51_3bdba644e3dd 6b5aad64_dafd_2e9e_4158_c8b5abc7f7f9["assign()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 6b5aad64_dafd_2e9e_4158_c8b5abc7f7f9 d72f5cc5_aa7a_2399_df67_14a5bc9119ab["invoke()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| d72f5cc5_aa7a_2399_df67_14a5bc9119ab 91f083c0_77eb_9272_3575_6d9cd76576c5["ainvoke()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 91f083c0_77eb_9272_3575_6d9cd76576c5 37c8f0c0_d521_95a3_6d74_5b0258f4b667["transform()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 37c8f0c0_d521_95a3_6d74_5b0258f4b667 3e489f1b_22c8_3bc5_db9c_0a5b99858658["atransform()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 3e489f1b_22c8_3bc5_db9c_0a5b99858658 8c4784fd_57ac_5659_f7cc_5e3c1aee0ed9["stream()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 8c4784fd_57ac_5659_f7cc_5e3c1aee0ed9 72357bc8_62bc_089c_9c98_383790e17bb9["astream()"] 8e2a3559_7880_8305_e0df_ce67ee25f95f -->|method| 72357bc8_62bc_089c_9c98_383790e17bb9
Relationship Graph
Source Code
libs/core/langchain_core/runnables/passthrough.py lines 74–346
class RunnablePassthrough(RunnableSerializable[Other, Other]):
"""Runnable to passthrough inputs unchanged or with additional keys.
This `Runnable` behaves almost like the identity function, except that it
can be configured to add additional keys to the output, if the input is a
dict.
The examples below demonstrate this `Runnable` works using a few simple
chains. The chains rely on simple lambdas to make the examples easy to execute
and experiment with.
Examples:
```python
from langchain_core.runnables import (
RunnableLambda,
RunnableParallel,
RunnablePassthrough,
)
runnable = RunnableParallel(
origin=RunnablePassthrough(), modified=lambda x: x + 1
)
runnable.invoke(1) # {'origin': 1, 'modified': 2}
def fake_llm(prompt: str) -> str: # Fake LLM for the example
return "completion"
chain = RunnableLambda(fake_llm) | {
"original": RunnablePassthrough(), # Original LLM output
"parsed": lambda text: text[::-1], # Parsing logic
}
chain.invoke("hello") # {'original': 'completion', 'parsed': 'noitelpmoc'}
```
In some cases, it may be useful to pass the input through while adding some
keys to the output. In this case, you can use the `assign` method:
```python
from langchain_core.runnables import RunnablePassthrough
def fake_llm(prompt: str) -> str: # Fake LLM for the example
return "completion"
runnable = {
"llm1": fake_llm,
"llm2": fake_llm,
} | RunnablePassthrough.assign(
total_chars=lambda inputs: len(inputs["llm1"] + inputs["llm2"])
)
runnable.invoke("hello")
# {'llm1': 'completion', 'llm2': 'completion', 'total_chars': 20}
```
"""
input_type: type[Other] | None = None
func: Callable[[Other], None] | Callable[[Other, RunnableConfig], None] | None = (
None
)
afunc: (
Callable[[Other], Awaitable[None]]
| Callable[[Other, RunnableConfig], Awaitable[None]]
| None
) = None
@override
def __repr_args__(self) -> Any:
# Without this repr(self) raises a RecursionError
# See https://github.com/pydantic/pydantic/issues/7327
return []
def __init__(
self,
Source
Frequently Asked Questions
What is the RunnablePassthrough class?
RunnablePassthrough is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/passthrough.py.
Where is RunnablePassthrough defined?
RunnablePassthrough is defined in libs/core/langchain_core/runnables/passthrough.py at line 74.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free