Tools and bind_tools
A tool is a Python function a model can call. @tool turns a function into one, and model.bind_tools([...]) returns a new model that is allowed to request it.
Last updated: 27 Sep, 2026 · LangChain 1.4
A model on its own can only write text. A tool lets it look something up or take an action. The model does not run the tool; it asks for it, and your program runs it.
The @tool decorator and bind_tools
from langchain.tools import tool
@tool
def name(arg: str) -> str:
"""What the tool does (the model reads this)."""
return result
model_with_tools = model.bind_tools([name]) # returns a NEW modelTurning a function into a tool
Start by turning a plain function into a tool. The @tool decorator reads the type hints for the input schema and the docstring for the description the model sees.
from langchain.tools import tool
@tool
def lookup_order(order_id: str) -> str:
"""Look up the status of an order by its id.""" # the model reads this line
return f"Order {order_id}: shipped on 3 March."Calling the tool directly
Run the tool yourself with .invoke, passing its arguments as a dict. The model would ask for it, but here you call it directly to see what it returns.
print(lookup_order.invoke({"order_id": "A17"})) # call the tool with its argumentThe tool in a run
The tool and the call together:
from langchain.tools import tool
@tool
def lookup_order(order_id: str) -> str:
"""Look up the status of an order by its id."""
return f"Order {order_id}: shipped on 3 March."
print(lookup_order.invoke({"order_id": "A17"}))What @tool adds to a function
- The type hints are required: they define the tool's input schema.
- The docstring becomes the tool's description, which the model reads to decide when to call it.
bind_toolsreturns a NEW model that knows about the tool; the original model is unchanged.
Plain function vs @tool
| Plain function | @tool | |
|---|---|---|
| A model can request it | No | Yes, once bound |
| Has a schema | No | From the type hints |
| Has a description | No | From the docstring |
Where tools fit
- Any action an agent takes: search, look up an order, send an email, run a query.
- You give the model the tools; it chooses which to call and with what arguments.
bind_tools returns a new model, so assign it: model = model.bind_tools([...]). If you keep calling the old model, it will never ask for a tool.Related
- Previous: Chat models: init_chat_model
- Next: ToolNode and tools_condition
- Reference: Tools
- Add a second argument to
lookup_orderand call it. - Write a
refundtool and give it a clear docstring.
You understood something today that you didn't yesterday.