From 07d802d0887f156690fc319cd364876f2872377a Mon Sep 17 00:00:00 2001 From: Zander Chase <130414180+vowelparrot@users.noreply.github.com> Date: Mon, 26 Jun 2023 22:57:52 -0700 Subject: [PATCH] Don't raise error if parent not found (#6538) Done so that you can pass in a run from the low level api --- langchain/callbacks/tracers/base.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/langchain/callbacks/tracers/base.py b/langchain/callbacks/tracers/base.py index dd0c1183558..6cfad4d431e 100644 --- a/langchain/callbacks/tracers/base.py +++ b/langchain/callbacks/tracers/base.py @@ -1,6 +1,7 @@ """Base interfaces for tracing runs.""" from __future__ import annotations +import logging from abc import ABC, abstractmethod from datetime import datetime from typing import Any, Dict, List, Optional, Union @@ -10,6 +11,8 @@ from langchain.callbacks.base import BaseCallbackHandler from langchain.callbacks.tracers.schemas import Run, RunTypeEnum from langchain.schema import LLMResult +logger = logging.getLogger(__name__) + class TracerException(Exception): """Base class for exceptions in tracers module.""" @@ -41,9 +44,7 @@ class BaseTracer(BaseCallbackHandler, ABC): if parent_run: self._add_child_run(parent_run, run) else: - raise TracerException( - f"Parent run with UUID {run.parent_run_id} not found." - ) + logger.warning(f"Parent run with UUID {run.parent_run_id} not found.") self.run_map[str(run.id)] = run def _end_trace(self, run: Run) -> None: @@ -53,10 +54,8 @@ class BaseTracer(BaseCallbackHandler, ABC): else: parent_run = self.run_map.get(str(run.parent_run_id)) if parent_run is None: - raise TracerException( - f"Parent run with UUID {run.parent_run_id} not found." - ) - if ( + logger.warning(f"Parent run with UUID {run.parent_run_id} not found.") + elif ( run.child_execution_order is not None and parent_run.child_execution_order is not None and run.child_execution_order > parent_run.child_execution_order @@ -71,7 +70,8 @@ class BaseTracer(BaseCallbackHandler, ABC): parent_run = self.run_map.get(parent_run_id) if parent_run is None: - raise TracerException(f"Parent run with UUID {parent_run_id} not found.") + logger.warning(f"Parent run with UUID {parent_run_id} not found.") + return 1 if parent_run.child_execution_order is None: raise TracerException( f"Parent run with UUID {parent_run_id} has no child execution order."