From d67c8491c339cc885393e0bf394c22028253cc09 Mon Sep 17 00:00:00 2001 From: Ali Zulfiqar Date: Sat, 5 Sep 2026 22:14:06 +0500 Subject: [PATCH 1/2] fix(tools): preserve an explicitly empty description Signed-off-by: Ali Zulfiqar --- src/anthropic/lib/tools/_beta_functions.py | 2 +- tests/lib/tools/test_functions.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/anthropic/lib/tools/_beta_functions.py b/src/anthropic/lib/tools/_beta_functions.py index 6b49e1407..d9df60da5 100644 --- a/src/anthropic/lib/tools/_beta_functions.py +++ b/src/anthropic/lib/tools/_beta_functions.py @@ -172,7 +172,7 @@ def __init__( self._input_examples = input_examples self._strict = strict - self.description = description or self._get_description_from_docstring() + self.description = description if description is not None else self._get_description_from_docstring() if input_schema is not None: if isinstance(input_schema, type): diff --git a/tests/lib/tools/test_functions.py b/tests/lib/tools/test_functions.py index f7b1873be..89e5eb15f 100644 --- a/tests/lib/tools/test_functions.py +++ b/tests/lib/tools/test_functions.py @@ -560,3 +560,15 @@ async def fn(x: int) -> str: with pytest.raises(TypeError, match="needs an explicit input_schema"): beta_async_tool(name="noschema")(cast(Any, noschema_cm)) + + +@pytest.mark.parametrize("description", ["", "Replacement description", None]) +def test_explicit_tool_description(description: str | None) -> None: + def example() -> str: + """Original description.""" + return "ok" + + tool = beta_tool(example, description=description) + expected = "Original description." if description is None else description + assert tool.description == expected + assert tool.to_dict()["description"] == expected From 565ebb899e680620baedd39f7d200d3ffd564e2b Mon Sep 17 00:00:00 2001 From: Ali Zulfiqar Date: Sat, 5 Sep 2026 22:29:49 +0500 Subject: [PATCH 2/2] Address review feedback and strengthen regression coverage Signed-off-by: Ali Zulfiqar --- tests/lib/tools/test_functions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/tools/test_functions.py b/tests/lib/tools/test_functions.py index 89e5eb15f..95864595d 100644 --- a/tests/lib/tools/test_functions.py +++ b/tests/lib/tools/test_functions.py @@ -562,6 +562,7 @@ async def fn(x: int) -> str: beta_async_tool(name="noschema")(cast(Any, noschema_cm)) +@pytest.mark.skipif(PYDANTIC_V1, reason="only applicable in pydantic v2") @pytest.mark.parametrize("description", ["", "Replacement description", None]) def test_explicit_tool_description(description: str | None) -> None: def example() -> str: