-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Fix: Handle malformed tool calls from OpenAI using sanitizer #6844
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
base: main
Are you sure you want to change the base?
Fix: Handle malformed tool calls from OpenAI using sanitizer #6844
Conversation
@microsoft-github-policy-service agree |
python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py
Outdated
Show resolved
Hide resolved
@microsoft-github-policy-service agree |
Hi @ekzhu, just following up on this PR — I’ve made the requested changes and confirmed all CLA requirements are now satisfied. Let me know if there's anything else needed from my side. Thanks! |
Hi again @ekzhu, just following up in case this PR got buried. Happy to rebase or resolve conflicts if needed — just let me know. Thanks again for reviewing earlier! |
Hi @PranjalPragya, Could you please resolve the merge conflicts with the main branch? Thanks! |
Hi @ekzhu / @tejas-dharani, I’ve resolved the merge conflicts with the main branch and committed the changes. All CLA requirements are satisfied, and all requested modifications have been applied. Please let me know if anything else is needed from my side for review. Thanks! |
Problem
Previously, when OpenAI returned a malformed tool_calls response — such as when function.arguments was None, an invalid type, or not a JSON string — it would cause the Autogen agent to crash.
This commonly occurred during tool call processing, especially when relying on external model behavior that couldn’t be guaranteed to be clean or well-formed.
Solution
This PR introduces a new sanitizer in autogen_core/utils/sanitizer.py that:
This enhances Autogen's fault-tolerance, especially during external API usage and multi-agent orchestration where malformed tool responses can silently derail entire chains.
Testing
A dedicated test (
test_sanitizer.py
) was added to:Notes
Checks