
azure-openai
#10474
pattern_mismatch_error
The function name does not match the expected pattern. Ensure it only includes letters, numbers, underscores, or hyphens.
This error has been identified and solved.
Reason
The 400
status error in the Azure OpenAI API, specifically the error message "Invalid 'messages.tool_calls.function.name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'," is occurring due to the following reasons:
Invalid Function Name
The function.name
field in the tool_calls
array does not conform to the expected pattern. The pattern requires the string to consist only of letters (both uppercase and lowercase), numbers, underscores, and hyphens (^[a-zA-Z0-9_-]+$
).
Request Validation
The API is strictly validating the input parameters, and any deviation from the expected format results in a 400 Bad Request
error. This includes ensuring that the function name does not contain spaces, special characters, or non-Latin characters.
Solution
To fix the 400
status error in the Azure OpenAI API due to the invalid function.name
pattern, you need to ensure the function name complies with the specified format. Here are the key actions to take:
Check and correct the
function.name
field to only include letters (both uppercase and lowercase), numbers, underscores, and hyphens.Remove any spaces, special characters, or non-Latin characters from the function name.
Verify that the function name matches the pattern
^[a-zA-Z0-9_-]+$
.
By ensuring the function name adheres to these guidelines, you can resolve the error and successfully submit your API request.
Suggested Links
https://portkey.ai/error-library/prompt-error-10016
https://community.openai.com/t/error-400-related-to-size-of-string/840368
https://cheatsheet.md/chatgpt-cheatsheet/openai-api-error-axioserror-request-failed-status-code-400
https://github.com/home-assistant/core/issues/119015
https://learn.microsoft.com/en-us/answers/questions/1479386/azure-openai-api-calling-issue
https://learn.microsoft.com/fi-fi/azure/ai-services/openai/reference
https://learn.microsoft.com/en-us/azure/api-management/api-management-authenticate-authorize-azure-openai