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 Annotatedfrom langchain.tools import tool@tooldef 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'}
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.
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.