A model can call a function that does not exist: it misremembers a name, invents a plausible one, or calls a function from an earlier conversation. Running the name blindly is a bug, and ignoring it silently is worse. The OpenAI function calling guide shows the safe pattern in its own example router: if the name matches a known function, call it; otherwise raise an error naming the unknown function. The MCP tools specification agrees: an unknown tool is a protocol error, distinct from a tool execution error.
What you need
- A registry of the functions your application actually implements
- The tool call the model returned, with its name and arguments
- A rule for what to send back when the name is unknown
Step 1: Validate the name against the registry
Before running anything, check the called name against the list of functions you registered for this request. Never execute a name that is not in the registry, even if the arguments look valid.
Step 2: Return a clear error to the model
Send back an error naming the unknown function and listing the functions that are available. The model can then correct itself, where a silent failure leaves it guessing.
Step 3: Log the unknown call and check the cause
Record the unknown name and the prompt that produced it. If the same invented name appears repeatedly, the function descriptions or the system prompt are misleading the model, and they need rewriting.
Worked example: synthetic unknown function check
The table below is a synthetic example. It shows the expected result of handling unknown calls; no function was called.
| Called name | In registry? | Action |
|---|---|---|
| get_weather | Yes | Run it |
| delete_all_data | No | Error to model |
| get_horoscope | Yes | Run it |
| send_invoice_now | No | Error to model |
Expected result (UNTESTED). the two known functions run, and the two unknown names are rejected with a clear error. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- An unknown tool is a protocol error, while a failed known tool is a tool execution error: handle them differently.
- Tool execution errors should be given to the model so it can self-correct; protocol errors are less likely to be fixable by the model.
- Keep the number of functions available at the start of a turn small: the guide suggests fewer than 20 for higher accuracy.
- A model that repeatedly invents functions needs better descriptions, not a bigger registry.
