__init_subclass__() — langchain Function Reference
Architecture documentation for the __init_subclass__() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 89ef8934_385e_99ca_6def_16de079c0578["__init_subclass__()"] 5ebe56ae_0ac8_cb13_b5a9_ee567b924009["BaseTool"] 89ef8934_385e_99ca_6def_16de079c0578 -->|defined in| 5ebe56ae_0ac8_cb13_b5a9_ee567b924009 style 89ef8934_385e_99ca_6def_16de079c0578 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/tools/base.py lines 413–444
def __init_subclass__(cls, **kwargs: Any) -> None:
"""Validate the tool class definition during subclass creation.
Args:
**kwargs: Additional keyword arguments passed to the parent class.
Raises:
SchemaAnnotationError: If `args_schema` has incorrect type annotation.
"""
super().__init_subclass__(**kwargs)
args_schema_type = cls.__annotations__.get("args_schema", None)
if args_schema_type is not None and args_schema_type == BaseModel:
# Throw errors for common mis-annotations.
# TODO: Use get_args / get_origin and fully
# specify valid annotations.
typehint_mandate = """
class ChildTool(BaseTool):
...
args_schema: Type[BaseModel] = SchemaClass
..."""
name = cls.__name__
msg = (
f"Tool definition for {name} must include valid type annotations"
f" for argument 'args_schema' to behave as expected.\n"
f"Expected annotation of 'Type[BaseModel]'"
f" but got '{args_schema_type}'.\n"
f"Expected class looks like:\n"
f"{typehint_mandate}"
)
raise SchemaAnnotationError(msg)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does __init_subclass__() do?
__init_subclass__() is a function in the langchain codebase, defined in libs/core/langchain_core/tools/base.py.
Where is __init_subclass__() defined?
__init_subclass__() is defined in libs/core/langchain_core/tools/base.py at line 413.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free