fixaiprompt
All techniques
Glossary · Technique

Function Calling / Tool Use

Also known as: Tool use, Function tools, Structured invocation

Let the model decide when to invoke a real function or API instead of free-text answering. The foundation of every modern agent.

When to use it

  • When the model needs real data (current weather, DB lookups, search).
  • Agent workflows that act on the world (send emails, write files, query APIs).
  • Anywhere the model would otherwise hallucinate facts.
  • When you need structured machine-parseable output from a chat interface.

When not to use it

  • Pure-creative tasks (writing, brainstorming) where there's nothing to retrieve.
  • Trivial tasks where direct generation is faster and cheaper than the round-trip.
  • When you can't trust the model with the tool's permissions (always sandbox).

How it works

  1. 1Declare available functions as JSON-schema with name, description, and parameter shape.
  2. 2The model returns either a normal text response, or a structured call: { name: 'get_weather', arguments: { city: 'Tokyo' } }.
  3. 3Your code runs the real function with those arguments and returns the result to the model.
  4. 4Model uses the result to produce the final user-facing answer.
  5. 5Modern: parallel tool calls, multi-turn tool use, automatic schema generation.

Example

Lazy prompt
What's the weather in Tokyo? (The model will fabricate temperature data.)
Using the technique
(Define get_weather tool with city parameter, call it with the model's structured request, return the real data, model uses it in the final response.)

Common pitfalls

  • Bad function descriptions = wrong tool selection. The description is the prompt.
  • Models will sometimes invoke a tool when free-text would have worked, and vice-versa.
  • Returning huge tool outputs blows the context window — paginate or summarize first.
  • Security: never give tools un-audited access to dangerous side effects.

Where this came from

OpenAI introduced function calling June 2023. Anthropic followed with tool use. Now standard across all major LLM APIs.