AI Hints
LangChain · Lesson 39 of 120

Tool Schemas

What the model sees.

⏱ 2 min read▶ Video at 42:35🎓 Free
Watch this lesson in the LangChain courseWatch on YouTube ↗Full LangChain course

The model never sees your Python code. It sees a schema, a structured description of each tool, made from the name, the docstring, and the arguments.

Tool Schemas
From the video: Tool Schemas
  • Not your code
  • A schema
  • Name, docstring, args

Describing arguments

For richer tools, we can describe each argument. Annotated attaches a description to a parameter. Here, search books takes a genre, and an optional maximum price. Run it. The schema shows each argument, with its type, description, and default. This is exactly what helps the model fill arguments correctly.

schema.pypython
from typing import Annotated
from langchain.tools import tool

@tool
def search_books(
    genre: Annotated[str, "a genre, like 'fantasy' or 'crime'"],
    max_price: Annotated[float, "highest price in pounds"] = 20.0,
) -> list[str]:
    """Find books in stock by genre, under a maximum price."""
    return ["The Hobbit"] if genre == "fantasy" else []

for name, spec in search_books.args.items():
    print(name, "->", spec)
Output
genre -> {'description': "a genre, like 'fantasy' or 'crime'", 'title': 'Genre', 'type':
'string'}
max_price -> {'default': 20.0, 'description': 'highest price in pounds', 'title': 'Max
Price', 'type': 'number'}

Why descriptions matter

If a tool is called with the wrong arguments, or not called when it should be, the fix is usually in the description. Say what each argument means, give examples of valid values, and state units, like pounds or days. The model reads every word.

keyvalue
Wrong arguments?improve arg descriptions
Never called?improve the docstring
Examplesvalid values
Unitspounds, days

Summary

The model sees a schema built from your tool's name, docstring, and annotated arguments. Clear descriptions lead to correct calls. Next, giving tools to a model.

Key takeaways
  • Schema, not code
  • Annotated args
  • Descriptions matter
Next up: Binding Tools — bind_tools