pick() — langchain Function Reference
Architecture documentation for the pick() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 1ddfbd86_717b_2bb0_35ab_c2089cae789b["pick()"] 4a62481c_02cb_a5de_1833_50669d5351a6["Runnable"] 1ddfbd86_717b_2bb0_35ab_c2089cae789b -->|defined in| 4a62481c_02cb_a5de_1833_50669d5351a6 style 1ddfbd86_717b_2bb0_35ab_c2089cae789b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/base.py lines 709–770
def pick(self, keys: str | list[str]) -> RunnableSerializable[Any, Any]:
"""Pick keys from the output `dict` of this `Runnable`.
!!! example "Pick a single key"
```python
import json
from langchain_core.runnables import RunnableLambda, RunnableMap
as_str = RunnableLambda(str)
as_json = RunnableLambda(json.loads)
chain = RunnableMap(str=as_str, json=as_json)
chain.invoke("[1, 2, 3]")
# -> {"str": "[1, 2, 3]", "json": [1, 2, 3]}
json_only_chain = chain.pick("json")
json_only_chain.invoke("[1, 2, 3]")
# -> [1, 2, 3]
```
!!! example "Pick a list of keys"
```python
from typing import Any
import json
from langchain_core.runnables import RunnableLambda, RunnableMap
as_str = RunnableLambda(str)
as_json = RunnableLambda(json.loads)
def as_bytes(x: Any) -> bytes:
return bytes(x, "utf-8")
chain = RunnableMap(
str=as_str, json=as_json, bytes=RunnableLambda(as_bytes)
)
chain.invoke("[1, 2, 3]")
# -> {"str": "[1, 2, 3]", "json": [1, 2, 3], "bytes": b"[1, 2, 3]"}
json_and_bytes_chain = chain.pick(["json", "bytes"])
json_and_bytes_chain.invoke("[1, 2, 3]")
# -> {"json": [1, 2, 3], "bytes": b"[1, 2, 3]"}
```
Args:
keys: A key or list of keys to pick from the output dict.
Returns:
a new `Runnable`.
"""
# Import locally to prevent circular import
from langchain_core.runnables.passthrough import RunnablePick # noqa: PLC0415
return self | RunnablePick(keys)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does pick() do?
pick() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/base.py.
Where is pick() defined?
pick() is defined in libs/core/langchain_core/runnables/base.py at line 709.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free