From 36a226cda9d073379cc9043f808ab9db07cc2596 Mon Sep 17 00:00:00 2001 From: Muspi Merol Date: Wed, 19 Aug 2026 11:24:38 +0800 Subject: [PATCH] fix(langfuse): fold custom_tool_call into the function_call branch Keeps the payload build to a single dict literal so the type-discipline gate's LIT002 total stays at its ceiling. --- .../integrations/langfuse/langfuse_otel.py | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/litellm/integrations/langfuse/langfuse_otel.py b/litellm/integrations/langfuse/langfuse_otel.py index dfdd3f127e5..6b240dba52e 100644 --- a/litellm/integrations/langfuse/langfuse_otel.py +++ b/litellm/integrations/langfuse/langfuse_otel.py @@ -196,32 +196,27 @@ class LangfuseOtelLogger(OpenTelemetry): "content": getattr(getattr(item, "content", [{}])[0], "text", ""), } ) - elif item_type == "function_call": - arguments_str = getattr(item, "arguments", "{}") - arguments_obj = ( - safe_json_loads(arguments_str, default={}) - if isinstance(arguments_str, str) - else arguments_str - ) + elif item_type in ("function_call", "custom_tool_call"): + # A custom (freeform) tool carries its payload as a raw string under `input`, + # where a function call carries a JSON string under `arguments`. + if item_type == "custom_tool_call": + payload_key, payload_value = "input", getattr(item, "input", "") + else: + arguments_str = getattr(item, "arguments", "{}") + payload_key = "arguments" + payload_value = ( + safe_json_loads(arguments_str, default={}) + if isinstance(arguments_str, str) + else arguments_str + ) langfuse_tool_call = { "id": getattr(item, "id", ""), "name": getattr(item, "name", ""), "call_id": getattr(item, "call_id", ""), - "type": "function_call", - "arguments": arguments_obj, + "type": item_type, + payload_key: payload_value, } output_items_data.append(langfuse_tool_call) - elif item_type == "custom_tool_call": - # Custom (freeform) tools carry a raw string `input` instead of JSON `arguments` - output_items_data.append( - { - "id": getattr(item, "id", ""), - "name": getattr(item, "name", ""), - "call_id": getattr(item, "call_id", ""), - "type": "custom_tool_call", - "input": getattr(item, "input", ""), - } - ) if output_items_data: safe_set_attribute( span,