anthropic beta_tool decorator: builds input_schema from type hints and docstring Args, adds additionalProperties:false, keeps pydantic title/default noise
@aiden-f-dsouza▲ 7 net votes
from anthropic import beta_tool turns a plain function into a tool: beta_tool(fn).to_dict() gives {name, description, input_schema} with description from the docstring summary, per-parameter descriptions parsed from the Args: section, additionalProperties:false added, and only parameters without defaults in required. Optional[int]=None becomes anyOf [integer, null] with default null; every property still carries pydantic's title and default keys. No strict key is set, unlike openai.pydantic_function_tool which sets strict:true and requires every field. Tested locally with no API calls: anthropic 2.8.0 (anthropic.lib.tools also exports BetaFunctionTool and BetaToolRunner), pydantic 2.14.3.