Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Sanitize function names #10257

Merged
merged 5 commits into from
Jan 22, 2025

Conversation

SergeyMenshykh
Copy link
Member

Motivation and Context

Currently, if an AI model hallucinates a function name (e.g., bar.foo instead of the advertised bar-foo) that contains disallowed characters (not in the range of a-zA-Z0-9_-), SK identifies it as an error case and sends the error back to the model along with the original function call. Given that the original function call contains the disallowed function name, the request to the AI model fails with the error: Invalid 'messages[6].tool_calls[0].function.name': string does not match pattern. Expected a string that matches the pattern ^[a-zA-Z0-9_-]+$.

Description

This PR replaces disallowed characters in function names with an underscore for all function calls before sending them to the AI model. This fix prevents the request to the AI model from failing and allows the model to auto-recover.

More context: Function Calling Reliability ADR
Closes: #9850

@SergeyMenshykh SergeyMenshykh requested a review from a team as a code owner January 22, 2025 13:23
@SergeyMenshykh SergeyMenshykh self-assigned this Jan 22, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Jan 22, 2025
@SergeyMenshykh SergeyMenshykh added ai connector Anything related to AI connectors function_calling and removed kernel Issues or pull requests impacting the core kernel labels Jan 22, 2025
@markwallace-microsoft markwallace-microsoft added the kernel Issues or pull requests impacting the core kernel label Jan 22, 2025
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Jan 22, 2025
Merged via the queue into microsoft:main with commit e98155a Jan 22, 2025
17 checks passed
@SergeyMenshykh SergeyMenshykh deleted the sanitize-function-names branch January 22, 2025 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai connector Anything related to AI connectors function_calling kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: Done
Development

Successfully merging this pull request may close these issues.

Python: Auto function throwing "Error: Function call request for a function that wasnt defined"
3 participants