Skip to content

Commit

Permalink
fix(langchain): add run_id check on_llm_error (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
hassiebp authored Jan 27, 2025
1 parent 2a0964c commit 94b42d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions langfuse/callback/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,13 +897,14 @@ def on_llm_error(
) -> Any:
try:
self._log_debug_event("on_llm_error", run_id, parent_run_id, error=error)
self.runs[run_id] = self.runs[run_id].end(
status_message=str(error),
level="ERROR",
version=self.version,
input=kwargs.get("inputs"),
)
self._update_trace_and_remove_state(run_id, parent_run_id, error)
if run_id in self.runs:
self.runs[run_id] = self.runs[run_id].end(
status_message=str(error),
level="ERROR",
version=self.version,
input=kwargs.get("inputs"),
)
self._update_trace_and_remove_state(run_id, parent_run_id, error)

except Exception as e:
self.log.exception(e)
Expand Down
1 change: 1 addition & 0 deletions tests/test_core_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ def faulty_mask_func(data):
langfuse = Langfuse(debug=True, mask=faulty_mask_func)

trace = langfuse.trace(name="test_trace", input={"sensitive": "data"})
sleep(0.1)
trace.update(output={"more": "sensitive"})
langfuse.flush()

Expand Down
1 change: 1 addition & 0 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ def test_llama_index_dataset():
assert run.name == run_name
assert len(run.dataset_run_items) == 1
assert run.dataset_run_items[0].dataset_run_id == run.id
time.sleep(1)

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

Expand Down

0 comments on commit 94b42d3

Please sign in to comment.