From 5de59f92363e1b0c02152df8e91af4bbbb185861 Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Tue, 23 Jan 2024 07:54:47 -0800 Subject: [PATCH] Core[Patch] Parse tool input after on_start (#16430) For tracing, if a validation error occurs, currently it is attributed to the previous step of the chain. It would be nice to have the on_start and on_error callbacks called for tools when there is a validation error that occurs to more easily attribute the root-cause --- libs/core/langchain_core/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/core/langchain_core/tools.py b/libs/core/langchain_core/tools.py index b83a5cc8a7..a536da4c79 100644 --- a/libs/core/langchain_core/tools.py +++ b/libs/core/langchain_core/tools.py @@ -312,7 +312,6 @@ class ChildTool(BaseTool): **kwargs: Any, ) -> Any: """Run the tool.""" - parsed_input = self._parse_input(tool_input) if not self.verbose and verbose is not None: verbose_ = verbose else: @@ -341,6 +340,7 @@ class ChildTool(BaseTool): **kwargs, ) try: + parsed_input = self._parse_input(tool_input) tool_args, tool_kwargs = self._to_args_and_kwargs(parsed_input) observation = ( self._run(*tool_args, run_manager=run_manager, **tool_kwargs) @@ -392,7 +392,6 @@ class ChildTool(BaseTool): **kwargs: Any, ) -> Any: """Run the tool asynchronously.""" - parsed_input = self._parse_input(tool_input) if not self.verbose and verbose is not None: verbose_ = verbose else: @@ -416,6 +415,7 @@ class ChildTool(BaseTool): **kwargs, ) try: + parsed_input = self._parse_input(tool_input) # We then call the tool on the tool input to get an observation tool_args, tool_kwargs = self._to_args_and_kwargs(parsed_input) observation = (