Define LangChain tools with @tool and type hints
Answer: Tools extend what agents can do. They can fetch real-time data, execute code, query external databases, and take actions. Under the hood, tools are callable functions with well-defined inputs and outputs, and those are passed to a chat model. That model decides when to invoke a tool, using the conversation context and the input arguments to provide. The simplest way to create a tool is with the @tool decorator.
Define a tool
By default, the function's docstring becomes the tool's description, and that text helps the model decide when to use it. Type hints are required as they define the tool's input schema. Keep that docstring informative and concise so the model can tell when to use the tool. Prefer snake_case for tool names. Some model providers have issues with or reject names containing spaces or special characters. Sticking to alphanumeric characters, underscores, and hyphens helps to improve compatibility across providers.
Override the name with @tool("web_search") when you need something more descriptive than the function name. Override the auto-generated tool description with the description= argument for clearer model guidance. Define complex inputs with Pydantic models or JSON schemas, and pass them as args_schema.
| Name | Description | |---|---| | Name | The function name, or @tool("custom_name") | | Description | A description argument | | Input schema | Type hints, or args_schema with a Pydantic model or JSON schema |
What the reference docs add
Tools are classes that an Agent uses to interact with the world, and each tool has a description. The agent uses the description to choose the right tool for the job. create_schema_from_function creates a Pydantic schema from a function's signature. convert_runnable_to_tool is also listed.
See also
Claims
- id: C1 claim: The simplest way to create a tool is the @tool decorator. source: S1 evidence: "The simplest way to create a tool is with the @tool decorator"
- id: C3 claim: Type hints are required because they define the tool's input schema. source: S1 evidence: "Type hints are required as they define the tool"
- id: C4 claim: A tool's description is what an agent uses to choose it. source: S2 evidence: "Agent uses the description to choose the right tool"
Sources
- [S1] Tools. LangChain docs. https://docs.langchain.com/oss/python/langchain/tools . License: MIT. Accessed 2026-11-19.
- [S2] tools. LangChain Core reference. https://reference.langchain.com/python/langchain_core/tools/ . License: MIT. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: LangChain docs, Tools; LangChain Core reference, tools. MIT; MIT. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: LangChain docs, Tools; LangChain Core reference, tools. MIT; MIT.
Cite this
iinventedlight. 2026. "Define LangChain tools with @tool and type hints." iinventedlight Library, iil:note:xx1jf96r, version of 2026-11-19. https://iinventedlight.com/library/notes/langchain-custom-tools/. License: CC-BY-4.0.
@misc{iil_note_xx1jf96r,
author = {{iinventedlight}},
title = {{Define LangChain tools with @tool and type hints}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/langchain-custom-tools/},
note = {Permanent ID iil:note:xx1jf96r. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- langchain-custom-tools.table.json (table; CC-BY-4.0)
- langchain-custom-tools.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/langchain-custom-tools.md.