Home / Function/ _create_schema_from_function() — anthropic-sdk-python Function Reference

_create_schema_from_function() — anthropic-sdk-python Function Reference

Architecture documentation for the _create_schema_from_function() function in _beta_functions.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  3bf0e655_8383_b5ca_7c90_6b1d977bf9c8["_create_schema_from_function()"]
  001b1f9e_045c_b009_1c1f_58964c925505["BaseFunctionTool"]
  3bf0e655_8383_b5ca_7c90_6b1d977bf9c8 -->|defined in| 001b1f9e_045c_b009_1c1f_58964c925505
  d9fcf820_8cac_9db2_dcbc_d9b37c4e6ce0["__init__()"]
  d9fcf820_8cac_9db2_dcbc_d9b37c4e6ce0 -->|calls| 3bf0e655_8383_b5ca_7c90_6b1d977bf9c8
  a4ecbe26_788b_b335_0183_047d4c54bf71["kw_arguments_schema()"]
  3bf0e655_8383_b5ca_7c90_6b1d977bf9c8 -->|calls| a4ecbe26_788b_b335_0183_047d4c54bf71
  style 3bf0e655_8383_b5ca_7c90_6b1d977bf9c8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/lib/tools/_beta_functions.py lines 128–170

    def _create_schema_from_function(self) -> InputSchema:
        """Create JSON schema from function signature using pydantic."""

        from pydantic_core import CoreSchema
        from pydantic.json_schema import JsonSchemaValue, GenerateJsonSchema
        from pydantic_core.core_schema import ArgumentsParameter

        class CustomGenerateJsonSchema(GenerateJsonSchema):
            def __init__(self, *, func: Callable[..., Any], parsed_docstring: Any) -> None:
                super().__init__()
                self._func = func
                self._parsed_docstring = parsed_docstring

            def __call__(self, *_args: Any, **_kwds: Any) -> "CustomGenerateJsonSchema":  # noqa: ARG002
                return self

            @override
            def kw_arguments_schema(
                self,
                arguments: "list[ArgumentsParameter]",
                var_kwargs_schema: CoreSchema | None,
            ) -> JsonSchemaValue:
                schema = super().kw_arguments_schema(arguments, var_kwargs_schema)
                if schema.get("type") != "object":
                    return schema

                properties = schema.get("properties")
                if not properties or not is_dict(properties):
                    return schema

                # Add parameter descriptions from docstring
                for param in self._parsed_docstring.params:
                    prop_schema = properties.get(param.arg_name)
                    if not prop_schema or not is_dict(prop_schema):
                        continue

                    if param.description and "description" not in prop_schema:
                        prop_schema["description"] = param.description

                return schema

        schema_generator = CustomGenerateJsonSchema(func=self.func, parsed_docstring=self._parsed_docstring)
        return self._adapter.json_schema(schema_generator=schema_generator)  # type: ignore

Subdomains

Called By

Frequently Asked Questions

What does _create_schema_from_function() do?
_create_schema_from_function() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/lib/tools/_beta_functions.py.
Where is _create_schema_from_function() defined?
_create_schema_from_function() is defined in src/anthropic/lib/tools/_beta_functions.py at line 128.
What does _create_schema_from_function() call?
_create_schema_from_function() calls 1 function(s): kw_arguments_schema.
What calls _create_schema_from_function()?
_create_schema_from_function() is called by 1 function(s): __init__.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free