What Is Function Calling? How LLMs Call Tools with JSON
Hand over a schema, let the model pick arguments, return the result
Short version: function calling doesn't make the model run anything. It hands back JSON that says "please call this function with these arguments," and your code does the running. After reading this you can wire that loop yourself and tell it apart from structured outputs and MCP.
One round trip
You send a list of tools (name, description, JSON Schema) with the request. If the model decides it needs one, it returns a call instead of text. Claude replies with stop_reason tool_use and a tool_use block. OpenAI returns a function call with a name and the arguments as a JSON string.
Your code actually runs it, then sends the result back tagged with the call id (in Claude, tool_use_id on a tool_result). The model reads the result and answers, or calls again.
{"type": "tool_use", "id": "toolu_01...", "name": "get_weather", "input": {"location": "Tokyo"}}
What I found in our own code
The internal chat feature in this repo runs the same loop (on Azure OpenAI). Reading it, two things stood out.
A loop cap. Call → result → call again can go on forever, so it stops at 5 (MAX_TOOL_ITERATIONS = 5). Without it, a model that keeps calling the same tool just burns money.
Broken arguments. When the argument JSON fails to parse, our code logs it, swaps in an empty hash {}, and runs the tool anyway. I fed a truncated JSON ({"name": "nega) through rails runner and got {} back. For a search tool, that means a search with no filter.
I assumed an error would stop things. It didn't. A better fix is to return the parse failure to the model as the tool result. Unknown tool names already work that way and come back as {"error": "Unknown function: ..."}. These days you can also put strict: true on a tool definition to enforce the schema (both Claude and OpenAI support it).
How it differs from structured outputs and MCP
Function calling model says "call this" → your code runs it → you feed the result back
Structured outputs the answer itself comes back as schema-shaped JSON → nothing to run
MCP a standard for where and how tools are fetched → they still reach the model as tool definitions
If all you need is JSON out, like classification or extraction, structured outputs are simpler. If you have to read from or change an outside system, use function calling. Once you want the same tools across several apps or clients, wrap them in MCP. More on that in the MCP post.
Be careful with
The model will call write tools just as confidently. For delete, payment or email tools, put a human confirmation in the loop, or don't hand them over at all. I wrote about blocking writes at the DB permission level when an AI reads production data in this post.
If you want to hook AI into an internal system but can't decide which tools to expose and how far, feel free to ask negabaro. We can start by sorting out the tool list and permissions together.
Key Concepts
Send the tool list (name, description, JSON Schema) with the request
The model returns a call instead of text (Claude: stop_reason tool_use + a tool_use block)
Your code validates the arguments and runs it — don't quietly turn a parse failure into {}
Send the result back tagged with the call id (Claude: tool_use_id on tool_result)
The model answers or calls again — cap the loop
Pros
- ✓ Fills gaps with tools: live data, math, internal systems
- ✓ Arguments arrive as JSON, easy to handle in code
- ✓ Execution stays in your code, so you know where to put the guard
Cons
- ✗ The model can pick the wrong tool or arguments
- ✗ Write tools need their own permissions or human sign-off
- ✗ More round trips mean more tokens and latency