Snippet · Building with models
Define a tool for a model to call
The description is the interface. Write it like documentation.
I want the model to be able to <what the tool does>. Write the tool definition: - A name that says what it does. - A description written for a reader who has never seen my system: what it does, when to use it, and explicitly when NOT to. - Every parameter typed, described, and marked required or optional. No parameter whose meaning needs outside knowledge. - What it returns, including what it returns when there's no result. Then the handler: - Validate every argument. The model can and will send nonsense. - Never let a tool argument reach a query, a shell, or a file path unescaped. - Return errors as data the model can act on, not exceptions. Tell me the three ways the model is most likely to misuse this.
"When NOT to use this" prevents more bad calls than any amount of describing when to use it. Without it, a plausible-sounding tool gets called for everything.