Principle:Langchain ai Langchain Tool Definition
| Knowledge Sources | |
|---|---|
| Domains | NLP, Tool_Use, Agentic_AI |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
A schema-driven mechanism for declaring executable capabilities that LLMs can invoke by specifying function names and arguments in structured format.
Description
Tool definition creates a bridge between human-written functions and LLM decision-making. A tool in LangChain consists of:
- Name: A unique identifier the model uses to select the tool
- Description: Natural language explanation helping the model decide when to use it
- Args schema: A JSON Schema (derived from Pydantic models or function signatures) defining the expected input parameters
- Execution logic: The actual Python function that runs when the tool is called
LangChain provides multiple ways to define tools: the @tool decorator (for functions), BaseTool subclassing (for complex tools), and Pydantic models (for schema-only definitions).
Usage
Define tools when building agentic applications where the LLM needs to interact with external systems (APIs, databases, file systems) or perform computations that it cannot do through text generation alone.
Theoretical Basis
Tool definition follows the capability declaration pattern from the Toolformer approach:
# Abstract tool interface
tool = {
"name": "search_web",
"description": "Search the web for current information",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"}
},
"required": ["query"]
}
}
The JSON Schema is generated automatically from Python type hints and docstrings, reducing the gap between code and LLM-readable specifications.