Skip to content

Prevent invoking functions when call has recorded argument exception (#7799) - #7902

Open
Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:fix/ficc-parse-exception
Open

Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:fix/ficc-parse-exception

Conversation

@Manish-1kumar

@Manish-1kumar Manish-1kumar commented Nov 1, 2026 •

Copy link
Copy Markdown

Description

Resolves #7799.

When an inner chat client encounters an argument parsing error (e.g. malformed JSON returned by the model), it sets callContent.Arguments = null and records the failure in callContent.Exception.

Previously, FunctionInvokingChatClient and FunctionInvokingRealtimeClientSession did not inspect context.CallContent.Exception before attempting invocation. If the target AIFunction had parameterless or optional parameters (e.g. (string opt = "default") => ...), the parameter binder succeeded using default argument values and executed the function with unintended inputs, returning a false success (RanToCompletion) back to the model.

This change:

  1. Inspects context.CallContent.Exception in InvokeFunctionAsync in both FunctionInvokingChatClient and FunctionInvokingRealtimeClientSession.
  2. If an argument parsing exception is recorded, returns a faulted ValueTask holding that exception without executing the underlying function.
  3. Propagates the exception through standard error handling, emitting a failed FunctionResultContent with the exception attached and updating consecutive error counts.
  4. Adds hermetic unit tests in FunctionInvokingChatClientTests verifying both sync and streaming execution for functions with optional parameters when callContent.Exception is present.

Customer Impact

Functions are protected against unintended execution with default parameter values when the model supplies invalid or corrupt arguments. The model receives an explicit tool error response, enabling it to recover.

Regression / Compatibility Analysis

  • Public API Surface: None.
  • Allocations: Zero heap allocations added.
  • Testing: 770 unit tests passed across all target frameworks (net10.0, net9.0, net8.0, net472).
Microsoft Reviewers: Open in CodeFlow

Guard against invoking functions when FunctionCallContent.Exception is not null in FunctionInvokingChatClient and FunctionInvokingRealtimeClientSession. Returns a failed result rather than attempting invocation with default arguments.

Fixes dotnet#7799
@Manish-1kumar
Manish-1kumar requested a review from a team as a code owner November 1, 2026 10:57
@github-actions github-actions Bot added the area-ai Microsoft.Extensions.AI libraries label Nov 1, 2026
@dotnet-comment-bot

Copy link
Copy Markdown
Collaborator

‼️ Found issues ‼️

Project Coverage Type Expected Actual
Microsoft.Extensions.Diagnostics.Testing Line 99 98.65 🔻
Microsoft.Extensions.Telemetry Line 93 92.75 🔻
Microsoft.Extensions.AI Line 89 88.39 🔻
Microsoft.Extensions.AI.OpenAI Line 75 68.24 🔻
Microsoft.Extensions.AI.OpenAI Branch 75 57.54 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Line 75 4.46 🔻
Microsoft.Extensions.DataIngestion.MarkItDown Branch 75 0 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Line 99 96.07 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring Branch 99 92.76 🔻
Microsoft.Extensions.Diagnostics.ResourceMonitoring.Kubernetes Line 99 97.73 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Line 75 42.11 🔻
Microsoft.Extensions.ServiceDiscovery.Abstractions Branch 75 42.86 🔻
Microsoft.Extensions.ServiceDiscovery.Dns Line 75 71.61 🔻
Microsoft.Extensions.ServiceDiscovery Line 75 68.88 🔻
Microsoft.Extensions.ServiceDiscovery Branch 75 71.43 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Line 75 73.85 🔻
Microsoft.Extensions.ServiceDiscovery.Yarp Branch 75 70 🔻
Microsoft.Extensions.VectorData.Abstractions Line 75 37.39 🔻
Microsoft.Extensions.VectorData.Abstractions Branch 75 22.73 🔻

🎉 Good job! The coverage increased 🎉
Update MinCodeCoverage in the project files.

Project Expected Actual
Microsoft.Extensions.Http.Diagnostics 94 95
Microsoft.Gen.BuildMetadata 97 100
Microsoft.Gen.MetadataExtractor 57 73
Microsoft.Gen.MetricsReports 67 69
Microsoft.Extensions.AI.Abstractions 82 86
Microsoft.Extensions.AI.Evaluation.NLP 0 78
Microsoft.Extensions.Caching.Hybrid 82 85
Microsoft.Extensions.DataIngestion 75 89
Microsoft.Extensions.DataIngestion.Markdig 75 90
Microsoft.Extensions.Http.Resilience 97 100

Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1658607&view=codecoverage-tab

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Microsoft.Extensions.AI] FunctionInvokingChatClient invokes calls with a recorded argument-parse exception

2 participants