Skip to content

Commit ded2a1f

Browse files
author
gaoanze888
authored
fix(core): allow deserializing RunnablePick (#39753)
1 parent 04ae744 commit ded2a1f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎libs/core/langchain_core/load/mapping.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@
548548
"passthrough",
549549
"RunnableAssign",
550550
),
551+
("langchain", "schema", "runnable", "RunnablePick"): (
552+
"langchain_core",
553+
"runnables",
554+
"passthrough",
555+
"RunnablePick",
556+
),
551557
("langchain", "schema", "runnable", "RunnableRetry"): (
552558
"langchain_core",
553559
"runnables",
@@ -963,6 +969,12 @@
963969
"passthrough",
964970
"RunnableAssign",
965971
),
972+
("langchain_core", "runnables", "passthrough", "RunnablePick"): (
973+
"langchain_core",
974+
"runnables",
975+
"passthrough",
976+
"RunnablePick",
977+
),
966978
("langchain_core", "runnables", "retry", "RunnableRetry"): (
967979
"langchain_core",
968980
"runnables",

‎libs/core/tests/unit_tests/load/test_serializable.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
HumanMessagePromptTemplate,
2424
PromptTemplate,
2525
)
26+
from langchain_core.runnables import RunnablePassthrough, RunnablePick
2627
from langchain_core.runnables.history import RunnableWithMessageHistory
2728
from langchain_core.tracers import log_stream
2829
from langchain_core.utils import from_env
@@ -1233,3 +1234,27 @@ def test_log_stream_does_not_use_all(self) -> None:
12331234
'allowed_objects="messages"' in source
12341235
or "allowed_objects='messages'" in source
12351236
)
1237+
1238+
1239+
def test_runnable_pick_roundtrips() -> None:
1240+
"""Test `RunnablePick` can be loaded back after being dumped.
1241+
1242+
Regression test: `RunnablePick` reports `is_lc_serializable()` and dumps fine,
1243+
but was missing from the deserialization mapping, so `load` rejected it while
1244+
its siblings in the same module round-tripped.
1245+
"""
1246+
original = RunnablePick(keys=["a"])
1247+
1248+
revived = load(dumpd(original))
1249+
1250+
assert isinstance(revived, RunnablePick)
1251+
assert revived.keys == ["a"]
1252+
1253+
1254+
def test_chain_using_pick_roundtrips() -> None:
1255+
"""Test a chain built with the public `.pick()` helper survives a round trip."""
1256+
chain = RunnablePassthrough().pick(["a"])
1257+
1258+
revived = load(dumpd(chain))
1259+
1260+
assert revived.invoke({"a": 1, "b": 2}) == {"a": 1}

0 commit comments

Comments
 (0)