Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions langfuse/callback/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
log.error(
f"Could not import langchain. The langchain integration will not work. {e}"
)
from typing import Any, Dict, List, Optional, Sequence, Union, cast
from typing import Any, Dict, List, Optional, Sequence, Set, Type, Union, cast
from uuid import UUID, uuid4

from langfuse.api.resources.ingestion.types.sdk_log_body import SdkLogBody
Expand Down Expand Up @@ -52,7 +52,13 @@
)

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

try:
from langgraph.errors import GraphBubbleUp
CONTROL_FLOW_EXCEPTION_TYPES.add(GraphBubbleUp)
except ImportError:
pass

class LangchainCallbackHandler(
LangchainBaseCallbackHandler, LangfuseBaseCallbackHandler
Expand Down Expand Up @@ -484,8 +490,13 @@ def on_chain_error(
try:
self._log_debug_event("on_chain_error", run_id, parent_run_id, error=error)
if run_id in self.runs:
if any(isinstance(error, t) for t in CONTROL_FLOW_EXCEPTION_TYPES):
level = None
else:
level = "ERROR"

self.runs[run_id] = self.runs[run_id].end(
level="ERROR",
level=level,
status_message=str(error),
version=self.version,
input=kwargs.get("inputs"),
Expand Down
Loading