Many function calling bugs don't throw an error. The request succeeds, the model answers in fluent prose, and the answer is wrong because your code gave it an incomplete or ambiguous conversation.
We ran the common mistakes against two open models on Mango Inference to see what happens. Below is each mistake, what the models did, and a tool loop that avoids all of them.
How does function calling work?
The model never runs your function. You describe your functions in the tools parameter, the model replies with the name and arguments of the function it wants, your code runs it, and you send the result back so the model can answer.

Most of these bugs happen inside that loop, because every round trip depends on your code passing back exactly what the model asked for, in the right order. The request and response formats are in the Tool calling guide.
What happens if a tool result is missing?
The model may invent the missing result. In our test, the API returned no error.
We asked: "Check if Mango Bistro and Seoul Table both have a table for 4 tomorrow at 7pm." Both models made two check_availability calls in one turn, one per restaurant. We sent back only the first result (Mango Bistro: available) and asked for the answer.
- DeepSeek V4.1 Flash: Runs: 5; Said both restaurants had a table: 5; Noticed and called the tool again: 0
- GLM-5.3-Flash: Runs: 5; Said both restaurants had a table: 1; Noticed and called the tool again: 4
※ Measured on November 27, 2026, with English prompts, default settings (reasoning on), 5 runs per model.
Nobody had checked Seoul Table. A booking agent built this way tells the user a table exists when it doesn't.
This usually happens when a loop handles only tool_calls[0], or when one tool raises an exception and the code skips its result. Models can request several tools in one turn, and both models did so on every run here. Send one role: "tool" message for every call, matched by tool_call_id.
Why does the model call the tool with the wrong date?
Because it doesn't know today's date. When we asked "Check if Mango Bistro has a table for 4 tomorrow at 7pm" without saying what today was:
- In 6 of 10 runs (5 per model), the model called the tool anyway with a date it made up, such as 2025-01-02 or 2026-07-01.
- In the other 4, it asked the user for the date instead of calling the tool.
Put the current date (and the user's time zone, if it matters) in the system message. In every run where the prompt included today's date, both models turned "tomorrow" into the correct date.
Is arguments a dictionary?
No. tool_calls[].function.arguments is a JSON-encoded string. You have to parse it with json.loads before you use it, and parsing can fail.
Treat the parsed result as untrusted input. The model can leave out a required field, send a date in the wrong format, or name a tool you never defined. Validate the arguments before you run anything, especially for tools that write data or spend money.
What should you do when a tool fails?
Send the error back to the model as the tool result instead of raising an exception. A message like {"error": "invalid arguments: ..."} lets the model correct its arguments or tell the user what went wrong. An exception that kills the loop leaves the user with nothing, and a silently skipped result leads to the invented answers above.
Also cap the number of rounds. A model that keeps calling tools will otherwise loop until it runs out of context or budget.
What does a correct tool loop look like?
This loop sends today's date, parses and validates arguments, appends the assistant message before the results, answers every tool call, returns errors to the model, and stops after five rounds:
import datetime
import json
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.mangoboost.io/v1",
api_key=os.environ["MANGOINFERENCE_API_KEY"],
)
MODEL = "deepseek-ai/DeepSeek-V4.1-Flash-1017"
tools = [{
"type": "function",
"function": {
"name": "check_availability",
"description": "Check whether a restaurant has a free table. Date YYYY-MM-DD, time HH:MM (24h).",
"parameters": {
"type": "object",
"properties": {
"restaurant": {"type": "string"},
"date": {"type": "string"},
"time": {"type": "string"},
"party_size": {"type": "integer", "minimum": 1},
},
"required": ["restaurant", "date", "time", "party_size"],
},
},
}]
def check_availability(restaurant, date, time, party_size):
# Replace with your booking system. Fake data for the example.
return {"restaurant": restaurant, "available": restaurant != "Seoul Table"}
def run_tool(call):
if call.function.name != "check_availability":
return {"error": f"unknown tool: {call.function.name}"}
try:
args = json.loads(call.function.arguments) # a JSON string, not a dict
datetime.date.fromisoformat(args["date"])
return check_availability(**args)
except (json.JSONDecodeError, KeyError, TypeError, ValueError) as e:
return {"error": f"invalid arguments: {e}"} # let the model fix it
def ask(question, max_turns=5):
today = datetime.date.today().isoformat()
messages = [
{"role": "system", "content": f"Today is {today}."},
{"role": "user", "content": question},
]
for _ in range(max_turns):
resp = client.chat.completions.create(model=MODEL, messages=messages, tools=tools)
msg = resp.choices[0].message
if not msg.tool_calls:
return msg.content
messages.append(msg) # the assistant turn that asked for the tools
for call in msg.tool_calls: # one result for every call
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(run_tool(call)),
})
raise RuntimeError("too many tool rounds")
print(ask("Can Mango Bistro and Seoul Table both seat 4 tomorrow at 7pm?"))
When we ran it on November 27, 2026, the model called the tool for both restaurants and answered that Mango Bistro was available and Seoul Table was not, matching the fake data.
The same loop works with the other models on Mango Inference; all four list tools in their supported_features from GET /v1/models. If you need the final answer itself in a fixed JSON shape, see Structured output.
To get an API key and run this loop, start with the Quickstart.
Building an agent that calls your own tools?
If you are planning an agent on top of your own APIs and want to talk through models, tool design or deployment options for your workload, contact us.














