File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -978,22 +978,25 @@ def on_tool_start(
978978 observation_type = self ._get_observation_type_from_serialized (
979979 serialized , "tool" , ** kwargs
980980 )
981+ tool_input = kwargs .get ("inputs" )
982+ if tool_input is None :
983+ tool_input = input_str
981984
982985 parent_observation = self ._get_parent_observation (parent_run_id )
983986 if isinstance (parent_observation , Langfuse ):
984987 span = parent_observation .start_observation (
985988 trace_context = self ._trace_context ,
986989 name = self .get_langchain_run_name (serialized , ** kwargs ),
987990 as_type = observation_type ,
988- input = input_str ,
991+ input = tool_input ,
989992 metadata = meta ,
990993 level = "DEBUG" if tags and LANGSMITH_TAG_HIDDEN in tags else None ,
991994 )
992995 else :
993996 span = parent_observation .start_observation (
994997 name = self .get_langchain_run_name (serialized , ** kwargs ),
995998 as_type = observation_type ,
996- input = input_str ,
999+ input = tool_input ,
9971000 metadata = meta ,
9981001 level = "DEBUG" if tags and LANGSMITH_TAG_HIDDEN in tags else None ,
9991002 )
Original file line number Diff line number Diff line change @@ -791,6 +791,33 @@ class DummyControlFlowError(RuntimeError):
791791 assert not _has_run_state (handler , retriever_run_id )
792792
793793
794+ def test_tool_start_prefers_structured_inputs_when_available (
795+ langfuse_memory_client , get_span , json_attr
796+ ):
797+ handler = CallbackHandler ()
798+ run_id = uuid4 ()
799+ structured_inputs = {
800+ "path" : "/tmp/example.md" ,
801+ "content" : '# Title\n \n This has "quotes" and JSON-like text: {"a": 1}' ,
802+ }
803+
804+ handler .on_tool_start (
805+ {"name" : "write_document" },
806+ str (structured_inputs ),
807+ run_id = run_id ,
808+ inputs = structured_inputs ,
809+ )
810+ handler .on_tool_end ("ok" , run_id = run_id )
811+
812+ langfuse_memory_client .flush ()
813+ span = get_span ("write_document" )
814+
815+ assert (
816+ json_attr (span , LangfuseOtelSpanAttributes .OBSERVATION_INPUT )
817+ == structured_inputs
818+ )
819+
820+
794821def test_handled_tool_error_marks_observation_error (
795822 langfuse_memory_client , get_span , json_attr
796823):
You can’t perform that action at this time.
0 commit comments