OpenAIError
openai.OpenAIError
Stack trace
openai.OpenAIError: Function tool call output not submitted. The assistant did not provide the required function call output in the response.
Why it happens
When using OpenAI's function calling feature, the assistant must include a function call output in its response. This error occurs if the assistant returns a message without the required function call data, often due to prompt misconfiguration or missing function definitions in the API call.
Detection
Check the API response for the presence of the 'function_call' field in the message object; if missing when expected, log and handle the error before processing the output.
Causes & fixes
The functions parameter was omitted or empty in the chat.completions.create call.
Include the functions list with properly defined function schemas in the API call to enable function calling.
The prompt or system message does not instruct the model to use function calls.
Add clear instructions in the system or user messages to trigger function calls, such as 'Use the function to get data.'
Using a model that does not support function calling or an outdated SDK version.
Use a supported model like gpt-4o or gpt-4o-mini and update the OpenAI SDK to the latest version.
Code: broken vs fixed
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role': 'user', 'content': 'Get me the weather.'}]
)
# This will raise error because no functions parameter is provided, so no function call output is submitted
print(response.choices[0].message.function_call) from openai import OpenAI
import os
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
functions = [
{
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City and state, e.g. San Francisco, CA"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
]
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Get me the weather."}],
functions=functions
)
print(response.choices[0].message.function_call) # Now outputs the function call data Workaround
Catch the OpenAIError and fallback to parsing the assistant's message content manually or retry the request with the functions parameter included.
Prevention
Always include the 'functions' parameter with correct function definitions and use models that support function calling to guarantee function call outputs.