Skip to content

Commit 94b42d3

Browse files
authored
fix(langchain): add run_id check on_llm_error (#1089)
1 parent 2a0964c commit 94b42d3

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

langfuse/callback/langchain.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -897,13 +897,14 @@ def on_llm_error(
897897
) -> Any:
898898
try:
899899
self._log_debug_event("on_llm_error", run_id, parent_run_id, error=error)
900-
self.runs[run_id] = self.runs[run_id].end(
901-
status_message=str(error),
902-
level="ERROR",
903-
version=self.version,
904-
input=kwargs.get("inputs"),
905-
)
906-
self._update_trace_and_remove_state(run_id, parent_run_id, error)
900+
if run_id in self.runs:
901+
self.runs[run_id] = self.runs[run_id].end(
902+
status_message=str(error),
903+
level="ERROR",
904+
version=self.version,
905+
input=kwargs.get("inputs"),
906+
)
907+
self._update_trace_and_remove_state(run_id, parent_run_id, error)
907908

908909
except Exception as e:
909910
self.log.exception(e)

tests/test_core_sdk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,7 @@ def faulty_mask_func(data):
15001500
langfuse = Langfuse(debug=True, mask=faulty_mask_func)
15011501

15021502
trace = langfuse.trace(name="test_trace", input={"sensitive": "data"})
1503+
sleep(0.1)
15031504
trace.update(output={"more": "sensitive"})
15041505
langfuse.flush()
15051506

tests/test_datasets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ def test_llama_index_dataset():
438438
assert run.name == run_name
439439
assert len(run.dataset_run_items) == 1
440440
assert run.dataset_run_items[0].dataset_run_id == run.id
441+
time.sleep(1)
441442

442443
trace = get_api().trace.get(handler.get_trace_id())
443444

0 commit comments

Comments
 (0)