.Net: OpenAI: throw clear error when tool result call ID is missing#13945
Open
Utricularor wants to merge 2 commits intomicrosoft:mainfrom
Open
.Net: OpenAI: throw clear error when tool result call ID is missing#13945Utricularor wants to merge 2 commits intomicrosoft:mainfrom
Utricularor wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses dotnet issue #10125 by failing fast when OpenAI tool result messages are missing a required tool call ID, preventing later null/invalid-id failures and providing a clearer error for callers.
Changes:
- Added explicit validation that
FunctionResultContent.CallIdis present when converting tool result messages into OpenAI request messages. - Throws an
ArgumentExceptionwith a clearer message when the call ID is missing/blank. - Added a regression unit test covering the missing call ID scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs | Adds call-id validation for tool result message conversion to OpenAI ToolChatMessage. |
| dotnet/src/Connectors/Connectors.OpenAI.UnitTests/Services/OpenAIChatCompletionServiceTests.cs | Adds regression test ensuring a clear ArgumentException is thrown when callId is missing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (string.IsNullOrWhiteSpace(resultContent.CallId)) | ||
| { | ||
| throw new ArgumentException("Function result message is missing a tool call id. Provide FunctionResultContent.CallId when sending tool results to OpenAI."); |
| } | ||
|
|
||
| [Fact] | ||
| public async Task FunctionResultsWithoutCallIdThrowClearExceptionAsync() |
Author
|
@microsoft-github-policy-service agree |
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
This pull request addresses issue #10125.
When a tool result is sent to the OpenAI connector without a tool call ID, the failure mode is not clear to contributors and users. In practice, this can happen when function calls are constructed synthetically (for example, without a provider-generated call ID). Instead of failing later in a less obvious way, this change makes the behavior explicit and easier to diagnose.
Problem Summary
The OpenAI request conversion path accepts tool result messages (AuthorRole.Tool) and transforms FunctionResultContent items into OpenAI tool messages.
Before this change:
Expected behavior:
What Changed
1) Added explicit validation in OpenAI tool-result conversion
File changed:
Change:
Why:
2) Added a regression unit test
File changed:
New test:
What it validates:
Why:
Validation
I ran targeted connector tests for this area:
Result:
Impact and Compatibility
Notes for Reviewers
As a newer contributor, I focused on making the fix minimal and explicit:
If maintainers prefer a different exception type or wording, I can update quickly.