Function calling lets a model emit structured tool calls instead of plain text. Your runtime executes the call, hands the result back, and the model continues. It is the productionised, schema-enforced cousin of ReAct — and the foundation of every serious AI integration shipping today.
Modern AI work falls into two halves. The first half is generating text. The second half is making things happen — sending an email, querying a database, charging a card, looking up a flight, updating a record. Plain text outputs cannot do those things. They can describe what the user wants, but a human or another piece of code has to translate that description into an actual API call.
Function calling closes that gap. The model produces a structured object — typically JSON — that names the function it wants to call and supplies the arguments. Your runtime parses that object, executes the corresponding code, and feeds the result back so the model can continue the conversation. The model never touches your APIs directly; your code does. The model just picks which tool to use and with what arguments.
A function-calling system has three moving parts: a tool catalog (JSON Schema definitions of every function the model is allowed to call), a model that supports function calling (every major provider does today), and a runtime loop that detects when the model wants to call a tool, executes it, and continues the conversation.
Think of it as hiring an assistant and giving them a small set of well-labelled forms to fill in. They cannot do anything you have not given them a form for. When they fill in a form, you process it. The forms are the schema; the assistant filling them in is the model; you executing the form is the runtime.
Plain text instructions
You are a CRM assistant. The user might ask you to look
up customers or create notes. If they do, respond with
something like:
LOOKUP_CUSTOMER name=John Doe
CREATE_NOTE customer_id=12345 text="..."
Use exactly these formats.
This works until it doesn't. The model occasionally writes LOOKUP_CUSTOMER John Doe without the name= prefix, uses curly quotes instead of straight ones, or invents a fourth command you didn't define. Your parser becomes a fragile rats' nest of regexes.
Tool schema + system prompt
// Tool catalog passed to the API alongside the prompt
[
{
"name": "lookup_customer",
"description": "Find a customer by name or email.
Returns id, name, email, plan, status.",
"parameters": {
"type": "object",
"properties": {
"name": { "type": "string", "description": "Full name" },
"email": { "type": "string", "description": "Email address" }
},
"anyOf": [ {"required":["name"]}, {"required":["email"]} ]
}
},
{
"name": "create_note",
"description": "Attach a note to a customer record.",
"parameters": {
"type": "object",
"properties": {
"customer_id": { "type": "string" },
"text": { "type": "string", "minLength": 1, "maxLength": 2000 }
},
"required": ["customer_id", "text"]
}
}
]
// System prompt
You are a CRM assistant. Use the provided tools to look
up customers and create notes. Never invent customer ids
— always look up first, then act on the returned id. If
unsure, ask the user before calling a tool that modifies
data.
The model returns a structured tool_call object validated against the schema. Your runtime executes the matching function and feeds the result back. No regex parsing, no fragile string formats, no curly-quote surprises.
description field is what the model reads to decide when to call a tool. Treat it as marketing copy aimed at the model — what does it do, when should it be used, what are the constraints?Tip: Tool descriptions are prompts in disguise. The same model that needs careful prompt engineering also needs careful tool description engineering. Spend time on these — they are the contract between the model and your APIs, and they pay back forever.
Build a tiny two-tool assistant: get_weather(city) and convert_temperature(value, from, to). Ask it questions that require zero, one, and two tool calls. Inspect the conversation log to see how it routes each question.
Take a working tool catalog and tighten one of the descriptions — add when-to-use guidance, edge cases, examples. Measure how often the model picks the right tool before and after the change. Description quality moves the needle more than people expect.
Add a deliberately failing tool that errors 30% of the time. Run a multi-step task and observe whether the model recovers (retries, asks the user, gives up gracefully). Update its description with explicit fail-handling guidance and retest.
Sign in to join the discussion and post comments.
Sign inPrompt Engineering for Image Generation
Turn words into stunning visuals. Master AI image generation tools like Midjourney, DALL·E 3, and Stable Diffusion with 18 focused tutorials — from first prompt to full brand identity.
Prompt Engineering for Developers
Use AI as your coding co-pilot. 18 tutorials on writing prompts to generate clean code, debug faster, write tests, build APIs, and ship better software.
Prompt Engineering for Business & Productivity
Use AI to work smarter — automate tasks, make better decisions, and communicate professionally. 12 practical business prompt tutorials for professionals.
Prompt Engineering for Education & Learning
Use AI as your personal tutor. Learn how to study faster, create lesson plans, generate practice questions, master languages, and prepare for competitive exams with smart prompts.
Prompt Engineering Projects & Real-World Applications
Twelve hands-on projects that turn prompt engineering theory into a portfolio. Build chatbots, content generators, RAG systems, and more.
Prompt Engineering for Data Science & Analytics
Supercharge your data workflows with AI. 15 practical tutorials on using prompt engineering for data cleaning, EDA, machine learning, SQL, visualisation, and more.