From aa2eb4606d73a616b50b1ea117e51de453d54baa Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Wed, 17 Jan 2024 10:32:10 -0800 Subject: [PATCH] Better error message on invalid use lf lastvalue channel --- langgraph/channels/last_value.py | 2 +- langgraph/pregel/__init__.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/langgraph/channels/last_value.py b/langgraph/channels/last_value.py index c585ceb86..858943c91 100644 --- a/langgraph/channels/last_value.py +++ b/langgraph/channels/last_value.py @@ -44,7 +44,7 @@ class LastValue(Generic[Value], BaseChannel[Value, Value, Value]): if len(values) == 0: return if len(values) != 1: - raise InvalidUpdateError() + raise InvalidUpdateError("LastValue can only receive one value per step.") self.value = values[-1] diff --git a/langgraph/pregel/__init__.py b/langgraph/pregel/__init__.py index b557b9c5d..6a714f271 100644 --- a/langgraph/pregel/__init__.py +++ b/langgraph/pregel/__init__.py @@ -46,6 +46,7 @@ from langgraph.channels.base import ( BaseChannel, ChannelsManager, EmptyChannelError, + InvalidUpdateError, create_checkpoint, ) from langgraph.channels.last_value import LastValue @@ -684,7 +685,12 @@ def _apply_writes( # Apply writes to channels for chan, vals in pending_writes_by_channel.items(): if chan in channels: - channels[chan].update(vals) + try: + channels[chan].update(vals) + except InvalidUpdateError as e: + raise InvalidUpdateError( + f"Invalid update for channel {chan}: {e}" + ) from e checkpoint["channel_versions"][chan] += 1 updated_channels.add(chan) else: