Skip to content

Commit e46d08d

Browse files
fix(langgraph): ignore control flow exceptions in LangChain callback (#1169) (#1180)
Co-authored-by: Max Friedrich <hallo@maxfriedrich.de>
1 parent 84420c6 commit e46d08d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

langfuse/callback/langchain.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
log.error(
1414
f"Could not import langchain. The langchain integration will not work. {e}"
1515
)
16-
from typing import Any, Dict, List, Optional, Sequence, Union, cast
16+
from typing import Any, Dict, List, Optional, Sequence, Set, Type, Union, cast
1717
from uuid import UUID, uuid4
1818

1919
from langfuse.api.resources.ingestion.types.sdk_log_body import SdkLogBody
@@ -52,7 +52,13 @@
5252
)
5353

5454
LANGSMITH_TAG_HIDDEN: str = "langsmith:hidden"
55+
CONTROL_FLOW_EXCEPTION_TYPES: Set[Type[BaseException]] = set()
5556

57+
try:
58+
from langgraph.errors import GraphBubbleUp
59+
CONTROL_FLOW_EXCEPTION_TYPES.add(GraphBubbleUp)
60+
except ImportError:
61+
pass
5662

5763
class LangchainCallbackHandler(
5864
LangchainBaseCallbackHandler, LangfuseBaseCallbackHandler
@@ -484,8 +490,13 @@ def on_chain_error(
484490
try:
485491
self._log_debug_event("on_chain_error", run_id, parent_run_id, error=error)
486492
if run_id in self.runs:
493+
if any(isinstance(error, t) for t in CONTROL_FLOW_EXCEPTION_TYPES):
494+
level = None
495+
else:
496+
level = "ERROR"
497+
487498
self.runs[run_id] = self.runs[run_id].end(
488-
level="ERROR",
499+
level=level,
489500
status_message=str(error),
490501
version=self.version,
491502
input=kwargs.get("inputs"),

0 commit comments

Comments
 (0)