Skip to content

Commit 58c6801

Browse files
valkryptonclaude
andcommitted
fix(anthropic): only include tool description if it exists
Avoids setting description to literal 'None' string when missing. Co-Authored-By: Claude 3.5 Sonnet <noreply@anthropic.com>
1 parent a709628 commit 58c6801

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

sentry_sdk/integrations/anthropic.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
truncate_and_annotate_messages,
1414
get_start_span_function,
1515
transform_anthropic_content_part,
16-
_normalize_data,
1716
)
1817
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
1918
from sentry_sdk.integrations import _check_minimum_version, DidNotEnable, Integration
@@ -379,13 +378,16 @@ def _transform_anthropic_tools(
379378

380379
transformed_tool = {
381380
"name": tool.get("name"),
382-
"description": tool.get("description"),
383381
"type": "function",
384382
}
385383

384+
description = tool.get("description")
385+
if description is not None:
386+
transformed_tool["description"] = description
387+
386388
input_schema = tool.get("input_schema")
387-
if input_schema:
388-
transformed_tool["parameters"] = _normalize_data(input_schema, unpack=False)
389+
if input_schema is not None:
390+
transformed_tool["parameters"] = input_schema
389391

390392
transformed_tools.append(transformed_tool)
391393

tests/integrations/anthropic/test_anthropic_tools_definitions.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@
4141
},
4242
"required": ["location"],
4343
},
44-
}
44+
},
45+
{
46+
"name": "no_description_tool",
47+
"input_schema": {
48+
"type": "object",
49+
"properties": {"arg1": {"type": "string"}},
50+
},
51+
},
4552
]
4653

4754

@@ -96,13 +103,21 @@ def test_tool_definitions_in_create_message(
96103
if send_default_pii and include_prompts:
97104
assert SPANDATA.GEN_AI_TOOL_DEFINITIONS in span["data"]
98105
tool_definitions = json.loads(span["data"][SPANDATA.GEN_AI_TOOL_DEFINITIONS])
99-
assert len(tool_definitions) == 1
106+
assert len(tool_definitions) == 2
107+
108+
# Check tool with description
100109
assert tool_definitions[0]["name"] == "get_weather"
101110
assert (
102111
tool_definitions[0]["description"]
103112
== "Get the current weather in a given location"
104113
)
105114
assert tool_definitions[0]["type"] == "function"
106115
assert tool_definitions[0]["parameters"] == TOOLS[0]["input_schema"]
116+
117+
# Check tool without description
118+
assert tool_definitions[1]["name"] == "no_description_tool"
119+
assert "description" not in tool_definitions[1]
120+
assert tool_definitions[1]["type"] == "function"
121+
assert tool_definitions[1]["parameters"] == TOOLS[1]["input_schema"]
107122
else:
108123
assert SPANDATA.GEN_AI_TOOL_DEFINITIONS not in span["data"]

0 commit comments

Comments
 (0)