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-coretoolsconverttool
    Function●Since v0.2

    tool

    Copy
    tool(
      name_or_callable: str | Callable | None = None,
      runnable: Runnable

    Used in Docs

    • Agent Evals
    • Agents
    • Build a custom SQL agent
    • Build a data analysis agent
    • Build a multi-source knowledge base with routing
    (59 more not shown)
    View source on GitHub
    |
    None
    =
    None
    ,
    *
    args
    :
    Any
    =
    (
    )
    ,
    description
    :
    str
    |
    None
    =
    None
    ,
    return_direct
    :
    bool
    =
    False
    ,
    args_schema
    :
    ArgsSchema
    |
    None
    =
    None
    ,
    infer_schema
    :
    bool
    =
    True
    ,
    response_format
    :
    Literal
    [
    'content'
    ,
    'content_and_artifact'
    ]
    =
    'content'
    ,
    parse_docstring
    :
    bool
    =
    False
    ,
    error_on_invalid_docstring
    :
    bool
    =
    True
    ,
    extras
    :
    dict
    [
    str
    ,
    Any
    ]
    |
    None
    =
    None
    )
    ->
    BaseTool
    |
    Callable
    [
    [
    Callable
    |
    Runnable
    ]
    ,
    BaseTool
    ]

    Parameters

    NameTypeDescription
    name_or_callablestr | Callable | None
    Default:None

    Optional name of the tool or the Callable to be converted to a tool.

    Overrides the function's name.

    Must be provided as a positional argument.

    runnableRunnable | None
    Default:None

    Optional Runnable to convert to a tool.

    Must be provided as a positional argument.

    descriptionstr | None
    Default:None
    *argsAny
    Default:()
    return_directbool
    Default:False
    args_schemaArgsSchema | None
    Default:None
    infer_schemabool
    Default:True
    response_formatLiteral['content', 'content_and_artifact']
    Default:'content'
    parse_docstringbool
    Default:False
    error_on_invalid_docstringbool
    Default:True
    extrasdict[str, Any] | None
    Default:None

    Convert Python functions and Runnables to LangChain tools.

    Can be used as a decorator with or without arguments to create tools from functions.

    Functions can have any signature - the tool will automatically infer input schemas unless disabled.

    Requirements
    • Functions should have type hints for proper schema inference.
    • Functions may accept multiple arguments and return types are flexible; outputs will be serialized if needed.
    • When using with Runnable, a string name must be provided.

    Optional description for the tool.

    Precedence for the tool description value is as follows:

    • This description argument (used even if docstring and/or args_schema are provided)
    • Tool function docstring (used even if args_schema is provided)
    • args_schema description (used only if description and docstring are not provided)

    Extra positional arguments.

    Must be empty.

    Whether to return directly from the tool rather than continuing the agent loop.

    Optional argument schema for user to specify.

    Whether to infer the schema of the arguments from the function's signature.

    This also makes the resultant tool accept a dictionary input to its run() function.

    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.

    If infer_schema and parse_docstring, will attempt to parse parameter descriptions from Google Style function docstrings.

    If parse_docstring is provided, configure whether to raise ValueError on invalid Google Style docstrings.

    Optional provider-specific extra fields for the tool.

    Used to pass configuration that doesn't fit into standard tool fields. Chat models should process known extras when constructing model payloads.

    Example

    For example, Anthropic-specific fields like cache_control, defer_loading, or input_examples.