Skip to content

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.

from langchain.tools import tool
@tool
def 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.

  1. Narrow name: get_order_status, not do_everything.
  2. Clear description: say when to use it and what it returns.
  3. Typed arguments: reject missing or malformed input early.
  4. Application checks: authenticate the caller and authorize the specific record.
  5. Small output: return what the next step needs, not an entire database row.

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.

Tool calling · create_agent · Middleware