By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Tool calling (or "function calling") lets AI agents interact with external systems—databases, APIs, calendars, or internal tools—by generating structured requests (e.g., JSON) that a middleware layer executes. This turns AI from a passive responder into an active workflow participant. Why it matters: Most business tasks require data or actions outside the model (e.g., fetching customer records, scheduling meetings, or triggering approvals). Example: A support agent uses tool calling to pull a user’s order history from a CRM, then drafts a personalized refund email—all in one conversation.
get_customer_orders
customer_id
date_range
{ "tool": "update_inventory", "parameters": { "product_id": "123", "quantity": -5 } }
delete_database
get_transaction
flag_fraud
transfer_funds
404
get_weather
get_data
charge_credit_card
create_ticket
send_email
get_inventory_levels
{ "product_id": { "type": "string", "description": "SKU or internal ID" } }
Example: Use OpenAI’s function calling docs or Anthropic’s tool use guide.
Build the middleware
product_id
{ "status": "success", "data": { "stock": 12 } }
Example: Use FastAPI to create an endpoint that handles get_inventory_levels and connects to your ERP.
Integrate with the AI
Example: In OpenAI’s API, include tools in the tools array and handle tool_calls in the response.
tools
tool_calls
Test edge cases
Example: Mock a 404 response and verify the AI says, "Product not found—try another ID."
Deploy with guardrails
approve_expense
get_customer_data
Log all tool calls for audits (e.g., "User X called update_pricing at 2:30 PM").
update_pricing
Monitor and iterate
Mistake: Letting the AI call tools without validation. Correction: Always validate inputs (e.g., check product_id format) and outputs (e.g., sanitize SQL queries) in the middleware. Why: Prevents injection attacks or malformed requests.
Mistake: Assuming the AI will always call the right tool. Correction: Test with ambiguous prompts (e.g., "Is this in stock?" vs. "What’s the inventory level?"). Refine tool descriptions to guide the AI. Why: The AI relies on descriptions to decide when to call a tool.
Mistake: Ignoring tool latency. Correction: Cache frequent queries (e.g., customer profiles) or batch requests (e.g., fetch all product data at once). Why: Slow tools degrade user experience.
Mistake: Exposing sensitive data in tool responses. Correction: Filter responses in the middleware (e.g., strip PII before returning customer data). Why: The AI might leak data in follow-up messages.
Mistake: Not handling tool errors. Correction: Design tools to return clear error codes (e.g., 404 for missing data) and train the AI to respond appropriately. Why: Users expect helpful feedback, not "An error occurred."
description
parameters
examples
gpt-4o
Scenario: Your team built an AI agent for a retail chatbot. A user asks, "Why was my order canceled?" The agent calls get_order_status but the tool returns 404: Order not found. The user insists the order exists.
get_order_status
404: Order not found
Question: What should the AI do next? Answer: The AI should:1. Apologize and ask for the order ID again (e.g., "I couldn’t find that order. Could you share the order ID or email used?").2. If the issue persists, escalate to a human (e.g., "Let me connect you with a support agent to resolve this."). Explanation: Never assume the user is wrong—validate inputs and provide a clear path to resolution.
get_weather(city: string)
{ "tool": "update_db", "data": { ... } }
charge_card
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.