Repository navigation
.Net: Fix: Enhance Function Argument Validation to Prevent Null Argument Exceptions in Tool Calls. - #9273
Merged
Roger Barreto (rogerbarreto) merged 6 commits intoOct 16, 2024
Conversation
Roger Barreto (rogerbarreto)
had a problem deploying
to
integration
October 15, 2024 12:38 — with
GitHub Actions
Error
Roger Barreto (rogerbarreto)
temporarily deployed
to
integration
October 15, 2024 12:40 — with
GitHub Actions
Inactive
Roger Barreto (rogerbarreto)
approved these changes
Oct 15, 2024
Member
|
Adit Sheth (@shethaadit) Please agree and we can merge it. |
Mark Wallace (markwallace-microsoft)
approved these changes
Oct 15, 2024
Contributor
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 15, 2024
Contributor
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
Adit Sheth (shethaadit)
temporarily deployed
to
integration
October 15, 2024 19:57 — with
GitHub Actions
Inactive
|
|
||
| // Ensure we're tracking the function's arguments. | ||
| if (update.FunctionArgumentsUpdate is not null) | ||
| if (update.FunctionArgumentsUpdate is not null && !update.FunctionArgumentsUpdate.ToMemory().IsEmpty) |
Member
There was a problem hiding this comment.
For my edification, why is this additional clause required? Is it trying to be an optimization, or is it fixing an issue? Based on a cursory look at the code, for the condition that clause is guarding, I'd have expected arguments.Append(update.FunctionArgumentsUpdate.ToString()) to simply be the equivalent of arguments.Append(""), since BinaryData.ToString() just does Encoding.UTF8.GetString on the supplied bytes, and passing in an empty set of bytes will lead that to return an empty string.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
1. Why is this change required?
This change is required to prevent null pointer exceptions caused by invalid or empty function argument updates, which could lead to system crashes or unexpected behavior during runtime.
2. What problem does it solve?
It addresses the issue where the
FunctionArgumentsUpdatewas not being properly validated, causing the Semantic Kernel to throw aSystem.ArgumentNullException. This update ensures proper validation of function arguments before processing.3. What scenario does it contribute to?
It improves the stability and reliability of tool call functions, particularly when interacting with external services like OpenAI, ensuring that memory operations are only executed on valid and non-empty inputs.
This PR resolves #9212.
Description
FunctionArgumentsUpdateby adding a check for both null and empty states, ensuring that invalid data is filtered out before processing.TrackStreamingToolingUpdatemethod, preventing memory issues and system crashes when receiving argument updates from external APIs.Unit Test Details
TrackStreamingToolingUpdatemethod when handlingnullvalues inFunctionArgumentsUpdate, ensuring it behaves correctly under various scenarios.nullcheck is removed in future changes, the test case will fail, providing an extra layer of protection against potential issues.Contribution Checklist