Repository navigation
Conversation
…ument When a JsonElement, JsonDocument or JsonNode argument cannot be deserialized to its parameter type, the JsonException thrown by the parameter marshaller now names the parameter. If a JSON string was supplied where a JSON object or array was expected (for example a double-encoded tool call argument), the message says so and suggests passing the JSON value directly. The exception type, path information and original exception (as InnerException) are preserved, and binding behavior is unchanged. Contributes to dotnet#7626.
Author
|
@dotnet-policy-service agree |
Collaborator
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1610124&view=codecoverage-tab |
Author
|
@eiriktsarpalis when you have a moment, could you take a look? It follows your feedback on #7626: the marshaller stays strict, and the Note Drafted with AI assistance (Claude Code) and reviewed by me. |
This branch has not been 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.
Contributes to #7626.
Following the feedback on #7630, this does not add any tolerance for double-encoded arguments. It only makes the failure easier to diagnose and correct.
Change
When a
JsonElement,JsonDocumentorJsonNodeargument cannot be deserialized to its parameter type, the parameter marshaller inAIFunctionFactorynow rethrows aJsonExceptionthat names the parameter. When a JSON string was supplied where the parameter's contract is an object, dictionary or collection, the message also says so and suggests passing the JSON value directly.The original message,
Path,LineNumber,BytePositionInLineand the original exception (asInnerException) are preserved. Binding behavior, the exception type and the public API are unchanged. No hint is added for types whose contract is a JSON primitive (for exampleGuidorDateTimeOffset), since a string is a valid representation for those.For the repro in the issue, the message is now:
Not included
With the default
IncludeDetailedErrors = false,FunctionInvokingChatClientstill sendsError: Function failed.to the model. Surfacing binding errors in that mode requires distinguishing them from exceptions thrown by the function body, which means new API, so I raised it on the issue instead.Tests
New tests in
AIFunctionFactoryTestcover JSON string arguments bound to object and collection parameters (viaJsonElement,JsonDocumentandJsonNode), and mismatches that must not get the hint (non-string values,Guid). All of them fail without the change.Microsoft.Extensions.AI.TestsandMicrosoft.Extensions.AI.Abstractions.Testspass on net8.0, net9.0, net10.0 and net472.Microsoft Reviewers: Open in CodeFlow