Lesson · 14 min
Tool use
Grok chooses a function, you run it, you send the result back.
Tool use (function calling) is how Grok reaches out of the model: look up an order, query a DB, hit a weather API. You declare tools with a name, description, and JSON schema. The model may return a tool call instead of a final answer. Your server runs it, appends a tool result message, and calls again.
- 01Describe tools narrowly. A kitchen-sink 'do_anything' tool will be called for everything and will be wrong.
- 02Validate arguments. The model can emit a schema-shaped lie.
- 03Never expose a tool that runs raw SQL or a shell from model-written strings.
- 04Cap loops. A tool that calls the model that calls the tool is how bills happen.