LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coretoolsbaseBaseTool
    Class●Since v0.2

    BaseTool

    Base class for all LangChain tools.

    This abstract class defines the interface that all LangChain tools must implement.

    Tools are components that can be called by agents to perform specific actions.

    Copy
    BaseTool(
        self,
        **kwargs: Any = {},
    )

    Bases

    RunnableSerializable[str | dict | ToolCall, Any]

    Used in Docs

    • Fmp data integration

    Constructors

    constructor
    __init__

    Attributes

    attribute
    name: str

    The unique name of the tool that clearly communicates its purpose.

    attribute
    description: str

    Used to tell the model how/when/why to use the tool.

    You can provide few-shot examples as a part of the description.

    attribute
    args_schema: Annotated[ArgsSchema | None, SkipValidation()]

    Pydantic model class to validate and parse the tool's input arguments.

    Args schema should be either:

    • A subclass of pydantic.BaseModel.
    • A subclass of pydantic.v1.BaseModel if accessing v1 namespace in pydantic 2
    • A JSON schema dict
    attribute
    return_direct: bool

    Whether to return the tool's output directly.

    Setting this to True means that after the tool is called, the AgentExecutor will stop looping.

    attribute
    verbose: bool

    Whether to log the tool's progress.

    attribute
    callbacks: Callbacks

    Callbacks to be called during tool execution.

    attribute
    tags: list[str] | None

    Optional list of tags associated with the tool.

    These tags will be associated with each call to this tool, and passed as arguments to the handlers defined in callbacks.

    You can use these to, e.g., identify a specific instance of a tool with its use case.

    attribute
    metadata: dict[str, Any] | None

    Optional metadata associated with the tool.

    This metadata will be associated with each call to this tool, and passed as arguments to the handlers defined in callbacks.

    You can use these to, e.g., identify a specific instance of a tool with its usecase.

    attribute
    handle_tool_error: bool | str | Callable[[ToolException], str] | None

    Handle the content of the ToolException thrown.

    attribute
    handle_validation_error: bool | str | Callable[[ValidationError | ValidationErrorV1], str] | None

    Handle the content of the ValidationError thrown.

    attribute
    response_format: Literal['content', 'content_and_artifact']

    The tool response format.

    If 'content' then the output of the tool is interpreted as the contents of a ToolMessage. If 'content_and_artifact' then the output is expected to be a two-tuple corresponding to the (content, artifact) of a ToolMessage.

    attribute
    extras: dict[str, Any] | None

    Optional provider-specific extra fields for the tool.

    This is used to pass provider-specific configuration that doesn't fit into standard tool fields.

    attribute
    model_config
    attribute
    is_single_input: bool

    Check if the tool accepts only a single input argument.

    attribute
    args: dict

    Get the tool's input arguments schema.

    attribute
    tool_call_schema: ArgsSchema

    Get the schema for tool calls, excluding injected arguments.

    Methods

    method
    get_input_schema

    The tool's input schema.

    method
    invoke
    method
    ainvoke
    method
    run

    Run the tool.

    method
    arun

    Run the tool asynchronously.

    Inherited fromRunnableSerializable

    Methods

    Mto_json
    —

    Convert the graph to a JSON-serializable format.

    Mconfigurable_fieldsMconfigurable_alternatives
    —

    Configure alternatives for Runnable objects that can be set at runtime.

    Inherited fromSerializable

    Attributes

    Alc_secrets: dict[str, str]
    —

    A map of constructor argument names to secret ids.

    Alc_attributes: dict
    —

    List of attribute names that should be included in the serialized kwargs.

    Methods

    Mis_lc_serializable
    —

    Return True as this class is serializable.

    Mget_lc_namespace
    —

    Get the namespace of the LangChain object.

    Mlc_id
    —

    Return a unique identifier for this class for serialization purposes.

    Mto_json
    —

    Convert the graph to a JSON-serializable format.

    Mto_json_not_implemented
    —

    Serialize a "not implemented" object.

    Inherited fromRunnable

    Attributes

    AInputType: AnyAOutputType: AnyAinput_schema: type[BaseModel]
    —

    The type of input this Runnable accepts specified as a Pydantic model.

    Aoutput_schema: type[BaseModel]
    —

    Output schema.

    Aconfig_specs: list[ConfigurableFieldSpec]

    Methods

    Mget_nameMget_input_jsonschema
    —

    Get a JSON schema that represents the input to the Runnable.

    Mget_output_schemaMget_output_jsonschema
    —

    Get a JSON schema that represents the output of the Runnable.

    Mconfig_schema
    —

    The type of config this Runnable accepts specified as a Pydantic model.

    Mget_config_jsonschema
    —

    Get a JSON schema that represents the config of the Runnable.

    Mget_graphMget_prompts
    —

    Return a list of prompts used by this Runnable.

    Mpipe
    —

    Pipe Runnable objects.

    Mpick
    —

    Pick keys from the output dict of this Runnable.

    Massign
    —

    Merge the Dict input with the output produced by the mapping argument.

    MbatchMbatch_as_completed
    —

    Run invoke in parallel on a list of inputs.

    MabatchMabatch_as_completed
    —

    Run ainvoke in parallel on a list of inputs.

    MstreamMastreamMastream_log
    —

    Stream all output from a Runnable, as reported to the callback system.

    Mastream_events
    —

    Generate a stream of events.

    MtransformMatransformMbind
    —

    Bind arguments to a Runnable, returning a new Runnable.

    Mwith_configMwith_listeners
    —

    Bind lifecycle listeners to a Runnable, returning a new Runnable.

    Mwith_alisteners
    —

    Bind async lifecycle listeners to a Runnable.

    Mwith_types
    —

    Bind input and output types to a Runnable, returning a new Runnable.

    Mwith_retry
    —

    Create a new Runnable that retries the original Runnable on exceptions.

    Mmap
    —

    Map a function to multiple iterables.

    Mwith_fallbacks
    —

    Add fallbacks to a Runnable, returning a new Runnable.

    Mas_tool
    —

    Create a BaseTool from a Runnable.

    View source on GitHub