Tools and schemas
A LangChain tool pairs executable code with a schema. The model sees the tool’s name, description, and arguments; your application executes the function.
Tiny example
Section titled “Tiny example”from langchain.tools import tool
@tooldef get_order_status(order_id: str) -> str: """Return the shipping status for one order the caller may access.""" return order_service.lookup(order_id)Type hints define the input schema. The docstring helps the model decide when the tool applies.
A useful tool contract
Section titled “A useful tool contract”- Narrow name:
get_order_status, notdo_everything. - Clear description: say when to use it and what it returns.
- Typed arguments: reject missing or malformed input early.
- Application checks: authenticate the caller and authorize the specific record.
- Small output: return what the next step needs, not an entire database row.
Failure note
Section titled “Failure note”Schema validation is not authorization. The model can request order_id="someone-elses-order"; the tool must enforce tenant and object permissions. Do not expose broad filesystem, SQL, or shell access because the description asks the model to be careful.