Skip to content

Commit 40cb0e1

Browse files
authored
fix(langchain): mitigate missing run_id on_chain_error (#1078)
1 parent a8ea85b commit 40cb0e1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

langfuse/callback/langchain.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,16 +481,21 @@ def on_chain_error(
481481
) -> None:
482482
try:
483483
self._log_debug_event("on_chain_error", run_id, parent_run_id, error=error)
484-
self.runs[run_id] = self.runs[run_id].end(
485-
level="ERROR",
486-
status_message=str(error),
487-
version=self.version,
488-
input=kwargs.get("inputs"),
489-
)
484+
if run_id in self.runs:
485+
self.runs[run_id] = self.runs[run_id].end(
486+
level="ERROR",
487+
status_message=str(error),
488+
version=self.version,
489+
input=kwargs.get("inputs"),
490+
)
490491

491-
self._update_trace_and_remove_state(
492-
run_id, parent_run_id, error, input=kwargs.get("inputs")
493-
)
492+
self._update_trace_and_remove_state(
493+
run_id, parent_run_id, error, input=kwargs.get("inputs")
494+
)
495+
else:
496+
self.log.warning(
497+
f"Run ID {run_id} already popped from run map. Could not update run with error message"
498+
)
494499

495500
except Exception as e:
496501
self.log.exception(e)

0 commit comments

Comments
 (0)