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-coretoolsstructuredStructuredToolfrom_function
    Method●Since v0.2

    from_function

    Copy
    from_function(
      cls,
      func: Callable | None = None,
      coroutine: Callable[
    View source on GitHub
    .
    .
    .
    ,
    Awaitable
    [
    Any
    ]
    ]
    |
    None
    =
    None
    ,
    name
    :
    str
    |
    None
    =
    None
    ,
    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
    =
    False
    ,
    **
    kwargs
    :
    Any
    =
    {
    }
    )
    ->
    StructuredTool

    Parameters

    NameTypeDescription
    funcCallable | None
    Default:None

    The function from which to create a tool.

    coroutineCallable[..., Awaitable[Any]] | None
    Default:None

    The async function from which to create a tool.

    namestr | None
    Default:None
    descriptionstr | None
    Default:None
    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:False
    **kwargsAny
    Default:{}

    Create tool from a given function.

    A classmethod that helps to create a tool from a function.

    The name of the tool.

    Defaults to the function name.

    The description of the tool.

    Defaults to the function docstring.

    Whether to return the result directly or as a callback.

    The schema of the tool's input arguments.

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

    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.

    Additional arguments to pass to the tool