RunnablePick Class — langchain Architecture
Architecture documentation for the RunnablePick class in passthrough.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b["RunnablePick"] 74fd3998_c4d9_f441_95fd_4c9845487771["passthrough.py"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|defined in| 74fd3998_c4d9_f441_95fd_4c9845487771 555ebd04_e39a_7fe8_621d_04cfc56ab9c9["__init__()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 555ebd04_e39a_7fe8_621d_04cfc56ab9c9 0b0e9575_88d8_2236_37d7_1e9b4f9790c0["is_lc_serializable()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 0b0e9575_88d8_2236_37d7_1e9b4f9790c0 a6886aea_bbbe_4233_90e7_19a34a921443["get_lc_namespace()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| a6886aea_bbbe_4233_90e7_19a34a921443 755392d8_23a2_6988_24ea_5387c3bdc34e["get_name()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 755392d8_23a2_6988_24ea_5387c3bdc34e ed0e5346_f7ce_b2b2_85e5_5fea0f6dc190["_pick()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| ed0e5346_f7ce_b2b2_85e5_5fea0f6dc190 34d0dee9_f20c_a9f2_4ad9_8167badcb6ba["invoke()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 34d0dee9_f20c_a9f2_4ad9_8167badcb6ba 11779e48_0194_ec05_338f_18488163ef07["_ainvoke()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 11779e48_0194_ec05_338f_18488163ef07 387bb0f8_7124_0c69_6e66_db7f9cd88faf["ainvoke()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 387bb0f8_7124_0c69_6e66_db7f9cd88faf 436fc40d_a965_4e5a_48ea_949cf2fd6576["_transform()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 436fc40d_a965_4e5a_48ea_949cf2fd6576 dad823e7_7ed7_b25b_3e0f_47d971187545["transform()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| dad823e7_7ed7_b25b_3e0f_47d971187545 5c6d1c67_4f5b_5be7_c629_8dc1ffdb7bc8["_atransform()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 5c6d1c67_4f5b_5be7_c629_8dc1ffdb7bc8 c3bfbc22_7e23_963a_4809_4467e4f75a04["atransform()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| c3bfbc22_7e23_963a_4809_4467e4f75a04 4ba6c08c_b6c8_f8f3_771e_286815a3c0e7["stream()"] c05fa707_3be2_95b6_c8b0_7e24cdcb8d9b -->|method| 4ba6c08c_b6c8_f8f3_771e_286815a3c0e7
Relationship Graph
Source Code
libs/core/langchain_core/runnables/passthrough.py lines 671–841
class RunnablePick(RunnableSerializable[dict[str, Any], Any]):
"""`Runnable` that picks keys from `dict[str, Any]` inputs.
`RunnablePick` class represents a `Runnable` that selectively picks keys from a
dictionary input. It allows you to specify one or more keys to extract
from the input dictionary.
!!! note "Return Type Behavior"
The return type depends on the `keys` parameter:
- When `keys` is a `str`: Returns the single value associated with that key
- When `keys` is a `list`: Returns a dictionary containing only the selected
keys
Example:
```python
from langchain_core.runnables.passthrough import RunnablePick
input_data = {
"name": "John",
"age": 30,
"city": "New York",
"country": "USA",
}
# Single key - returns the value directly
runnable_single = RunnablePick(keys="name")
result_single = runnable_single.invoke(input_data)
print(result_single) # Output: "John"
# Multiple keys - returns a dictionary
runnable_multiple = RunnablePick(keys=["name", "age"])
result_multiple = runnable_multiple.invoke(input_data)
print(result_multiple) # Output: {'name': 'John', 'age': 30}
```
"""
keys: str | list[str]
def __init__(self, keys: str | list[str], **kwargs: Any) -> None:
"""Create a `RunnablePick`.
Args:
keys: A single key or a list of keys to pick from the input dictionary.
"""
super().__init__(keys=keys, **kwargs)
@classmethod
@override
def is_lc_serializable(cls) -> bool:
"""Return `True` as this class is serializable."""
return True
@classmethod
@override
def get_lc_namespace(cls) -> list[str]:
"""Get the namespace of the LangChain object.
Returns:
`["langchain", "schema", "runnable"]`
"""
return ["langchain", "schema", "runnable"]
@override
def get_name(self, suffix: str | None = None, *, name: str | None = None) -> str:
name = (
name
or self.name
or "RunnablePick"
f"<{','.join([self.keys] if isinstance(self.keys, str) else self.keys)}>"
)
return super().get_name(suffix, name=name)
def _pick(self, value: dict[str, Any]) -> Any:
if not isinstance(value, dict):
msg = "The input to RunnablePassthrough.assign() must be a dict."
raise ValueError(msg) # noqa: TRY004
if isinstance(self.keys, str):
return value.get(self.keys)
picked = {k: value.get(k) for k in self.keys if k in value}
Source
Frequently Asked Questions
What is the RunnablePick class?
RunnablePick is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/passthrough.py.
Where is RunnablePick defined?
RunnablePick is defined in libs/core/langchain_core/runnables/passthrough.py at line 671.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free