AI agents & automation

AI Agent Tool Calling: Designing Safe CRM Actions

How to design AI agent tool calling for a CRM so the model can update leads and tasks without breaking data: narrow tools, server-side checks, confirmations and logs.

By Devang GandhiUpdated Nov 3, 20267 min read

AI agent tool calling is what turns a chatbot into something that does work: moving a lead to "site visit scheduled", logging a call outcome, creating a follow-up task. It is also where things can go wrong quickly, because the model is now writing to the same records your sales team depends on.

I have shipped tool calling in a production real-estate CRM, both from a live voice agent and through an MCP server that lets Claude act on a business's data. This post covers the design rules I follow so agents stay useful without becoming a risk.

TL;DR

Treat the model as an untrusted caller that proposes actions. Expose a few narrow, business-level tools with strict schemas. Enforce authentication, tenant scoping, permissions and validation on the server for every call. Require confirmation for destructive or bulk actions, and log every tool call with inputs and results.

key takeaways

  • In AI agent tool calling, the model only proposes actions; your server decides whether they are allowed and executes them.
  • Narrow, task-shaped tools with strict schemas are safer and more accurate than generic database access.
  • Permissions, tenant scoping and validation must live in code, never only in the system prompt.
  • Destructive or bulk actions need confirmation, and every tool call needs an audit log entry.

Design tools around business actions

The most common mistake is exposing something like run_query(collection, filter, update). It is flexible, but the model has to understand your schema perfectly, and one bad filter can change thousands of records.

Prefer narrow tools

Design tools the way you would design buttons in your UI. Each one does one business action with a small set of arguments.

Tool Arguments Risk level Confirmation
search_leads query, stage, limit (max 20) Read No
get_lead leadId Read No
add_note leadId, text Low write No
update_lead_stage leadId, stage (enum) Medium write Optional
create_follow_up leadId, dueAt, note Low write No
reassign_lead leadId, userId High write Yes
bulk_update Avoid exposing High Always, if at all

Write descriptions for the model

Tool descriptions are prompts. Say when to use the tool, when not to, and what each argument means. Use enums for stages and statuses so the model cannot invent a value like "hot-ish". Anthropic's tool use guide recommends detailed descriptions for exactly this reason.

Return useful results

Return compact, structured results: the updated record's key fields, or a clear error like {"error": "stage_not_allowed", "allowed": ["visit_scheduled", "lost"]}. Good errors let the model correct itself instead of guessing.

Enforce safety on the server

The system prompt can say "never reassign leads", but a prompt is guidance, not a control. Every safety rule needs to exist in the code that executes the tool.

The execution checklist

Every tool handler in my agents runs the same steps before touching data.

  1. Authenticate the caller and resolve the user and business from the session or token, never from model arguments.
  2. Scope every query to the current tenant, so a leadId from another business returns "not found".
  3. Check the user's role and plan permissions for this specific action.
  4. Validate arguments against the schema: types, enums, length limits, date ranges.
  5. Reject empty or overly broad filters on anything that writes.
  6. Execute the change in a single, small operation.
  7. Write an audit entry: who, which tool, arguments, result, model and timestamp.
  8. Return a compact result or a clear error.

Confirmation for risky actions

For actions like reassigning or bulk changes, the tool should return a pending confirmation rather than executing. In a chat interface, the user sees "Reassign 1 lead to the selected teammate? Confirm / Cancel". In a voice call, the agent reads back the change. Only a confirmed token executes the action.

Limits and loops

Cap the number of tool calls per conversation turn and per session. Agents occasionally loop, calling the same search repeatedly. A hard limit and a timeout stop runaway costs and accidental mass updates.

Tool calling in real time vs. through MCP

The same rules apply in two different settings I work with.

In a voice agent, tool calls happen mid-conversation, so they must be fast. Keep tools few and arguments simple, and do slow work like syncing to other systems after the call. The agent should say something natural while a tool runs.

Through MCP, an external AI client such as Claude discovers your tools from a server. The Model Context Protocol docs describe how servers expose tools; what they cannot do is enforce your business rules for you. OAuth gives you the user's identity, and your handlers still need the full checklist above.

How I built this in practice

I am a core engineer at Passdn Technologies on Antoc AI, a real-estate CRM used by 100+ firms in India with about 300K leads. Tool calling shows up in two places, both covered in the Antoc case study.

The first is our Hinglish AI voice calling agent, built with Sarvam for speech and Gemini through a voice platform. During a call, it updates the lead through tool calls: interest level, budget, preferred location, a site-visit time. We kept the tool set small because every extra tool adds tokens to the prompt, and in voice, latency is everything.

The second is a remote MCP server with OAuth that lets Claude act on a business's CRM data. Every tool resolves the business and user from the OAuth token, respects plan-based feature locking and role permissions, and scopes queries to the current organization, which matters because users can switch between multiple businesses.

The data layer underneath was hardened as leads grew past 300K: proper indexes, safe bulk operations that validate filters before running, and authentication plus network restrictions on the database. That hardening is what makes it reasonable to let an agent write at all.

Common mistakes

  • Exposing raw database queries as a tool instead of business actions.
  • Trusting userId or businessId arguments supplied by the model.
  • Relying on the system prompt to enforce permissions.
  • Allowing update operations with empty or broad filters.
  • No audit trail, so nobody can tell whether a change came from a person or the agent.
  • No cap on tool calls, letting an agent loop and rack up cost.

keep reading

FAQ

What is tool calling in an AI agent?+

Tool calling lets a language model request that your application run a specific function, such as updating a lead, with arguments the model fills in. Your code executes the function and returns the result so the model can continue.

How do I stop an AI agent from deleting or corrupting data?+

Do not give it delete tools unless absolutely needed, validate every argument on the server, scope every query to the current user and tenant, and require human confirmation for destructive or bulk actions. Prompt instructions alone are not a safety control.

Should an AI agent get direct database access?+

No. Give it a small set of business-level tools like update_lead_stage or create_follow_up instead of raw queries. That keeps permissions and validation in one place and makes the model's job easier.

Is function calling the same as MCP?+

They are related. Function calling is how a model requests a tool within one API call, while the Model Context Protocol is a standard way to expose tools from a server so different AI clients can discover and use them.

Devang Gandhi

AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me

Read next

More in AI agents & automation