OpenAI Model Called Function That Doesn't Exist
The model returned a tool_call for a function name that isn't in your dispatcher — a hallucinated tool. Common with vague system prompts, many similar tools, or older models. Prevent with strict: true, better naming, and defensive dispatch.
Enable strict: true on tools — model can only call functions in your array. If already using strict and still seeing this: check for typos in tool name, whitespace differences, or model calling non-existent tools when context suggests they should exist. Return an error tool message telling the model the function isn't available.
The Symptoms You're Seeing
tool_call.function.name = "search_documents" Your tools array has: ["search_web", "read_file", "list_files"] → Dispatch lookup fails; KeyError or missing case Model calls plausible-but-invented tools: "get_current_time" ← seems reasonable, doesn't exist "database_query" ← generic name, not defined "python_repl" ← inspired by other assistants Or slight variations: "search_web_v2" ← real tool: "search_web" "getWeather" ← real tool: "get_weather"
What Actually Causes This Error
Fixes That Work (Tested Nov 2026)
1Enable strict Mode
2Defensive Dispatcher with Fuzzy Match
3Improve Tool Descriptions to Reduce Hallucination
Never promise capabilities in the system prompt that aren't backed by defined tools. If you mention "you can query the database," the model will invent a query function even if you didn't provide one.
Preventing This Error Going Forward
- Enable
strict: true. Strongest defense against name drift. - Give tools distinct, specific names. Avoid generic verbs.
- Don't mention non-existent tools in system prompts. Model will invent them.
- Dispatcher returns error result, doesn't throw. Model can self-correct.
- Log unknown tool names. Post-mortem: which invented names appear?
- Use fuzzy match with caution. Fix root cause instead.
Researcher · AI Error Hub
Frequently Asked Questions
Yes for the function name — model constrained to exact names in tools array. Doesn't prevent the model from ATTEMPTING to reference non-existent tools in text output, only from creating tool_call objects for them.
Prefer strict mode to eliminate the case. If strict off (legacy), fuzzy match with high threshold (0.9+) and log every fuzzy hit. Fix by improving tool names/descriptions.
Yes. GPT-5 > GPT-4o > GPT-4o-mini in tool name reliability. o-series is very reliable due to internal reasoning about available tools. If hallucination is bad, upgrade model.
Yes — expose a list_available_tools function. Model can call it when uncertain. Especially useful for large tool arrays or dynamic tool availability.
Return error tool_result. If it persists across retries, the system prompt is likely implying capabilities you don't provide. Audit prompts; align stated capabilities with actual tools.
Related Errors
Ship Reliable Function Agents
Weekly deep dives on tool design, hallucination handling, and agent reliability. 12,000+ developers subscribe.
Subscribe Free →