Skip to content

.Net: fix(functions): preserve JSON converter errors - #14576

Open
King Star (jstar0) wants to merge 1 commit into
microsoft:mainfrom
jstar0:fix/kernel-function-jsonconverter-errors
Open

King Star (jstar0) wants to merge 1 commit into
microsoft:mainfrom
jstar0:fix/kernel-function-jsonconverter-errors

Conversation

@jstar0

Copy link
Copy Markdown
Contributor

Summary

Fixes #14575.

TryToDeserializeValue currently catches JsonException and falls back to the original argument, so converter validation messages are lost and reflection returns a generic type mismatch. Some connectors also provide a plain string without JSON quotes, preventing valid string-backed custom types from reaching their converter.

  • Keep syntactically valid JSON as-is, and let JsonException from deserialization or a custom converter reach the caller.
  • Encode a plain string as a JSON string only when it is not valid JSON.
  • Preserve the caller's trailing-comma, comment, and depth settings while checking the string input.

This is distinct from #14001, which supplies default serializer options but retains the exception fallback.

Validation

  • dotnet test dotnet/src/SemanticKernel.UnitTests/SemanticKernel.UnitTests.csproj --framework net10.0 --no-restore --filter 'FullyQualifiedName~KernelFunctionFromMethodTests' --logger 'console;verbosity=minimal' — 91 passed.
  • dotnet format dotnet/src/SemanticKernel.Core/SemanticKernel.Core.csproj --include dotnet/src/SemanticKernel.Core/Functions/KernelFunctionFromMethod.cs --verify-no-changes --no-restore — passed.
  • dotnet format dotnet/src/SemanticKernel.UnitTests/SemanticKernel.UnitTests.csproj --include dotnet/src/SemanticKernel.UnitTests/Functions/KernelFunctionFromMethodTests1.cs --verify-no-changes --no-restore — passed.
  • Four issue-specific regression cases failed on the original implementation and pass with this change.

Avoid falling back to raw arguments when JSON deserialization fails, so custom converter validation details reach the caller. Quote plain string arguments only when they are not valid JSON.

Fixes microsoft#14575.
@jstar0
King Star (jstar0) requested a review from a team as a code owner October 10, 2026 15:12
Copilot AI balanced review requested due to automatic review settings October 10, 2026 15:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@semantic-kernel-automation semantic-kernel-automation Bot added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Oct 10, 2026
@github-actions github-actions Bot changed the title fix(functions): preserve JSON converter errors .Net: fix(functions): preserve JSON converter errors Oct 10, 2026
@jstar0

Copy link
Copy Markdown
Contributor Author

Could a maintainer approve the initial pull_request workflow runs for this PR? GitHub currently marks dotnet-format, dotnet-build-and-test, Merge Gatekeeper, Spell Check, and Python Integration Tests as action_required, so hosted validation has not started. The focused .NET 10 tests and dotnet format checks passed locally. Thanks.

This branch was successfully deployed

1 active deployment
github-app-auth — 6ca055c1 Deployed Oct 10, 2026 by jstar0 via team_check #608
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Bug: KernelFunctionFromMethod hides a parameter's JsonConverter error; the model gets a cast error instead

2 participants