Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/anthropic/lib/tools/_beta_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/tools/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,16 @@ 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.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:
"""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