Skip to content
Tracon

ValidatingAIFunction

Namespace Tracon · Assembly Tracon.Core.dll

Wraps an AI.AIFunction with an IToolArgumentsValidator check that runs before every call.

public sealed class ValidatingAIFunction : DelegatingAIFunction

object ← AITool ← AIFunctionDeclaration ← AIFunction ← DelegatingAIFunction ← ValidatingAIFunction

DelegatingAIFunction.ToString(), DelegatingAIFunction.GetService(Type, object?), DelegatingAIFunction.Name, DelegatingAIFunction.Description, DelegatingAIFunction.JsonSchema, DelegatingAIFunction.ReturnJsonSchema, DelegatingAIFunction.JsonSerializerOptions, DelegatingAIFunction.UnderlyingMethod, DelegatingAIFunction.AdditionalProperties, AIFunction.InvokeAsync(AIFunctionArguments?, CancellationToken), AIFunction.AsDeclarationOnly(), AIFunction.UnderlyingMethod, AIFunction.JsonSerializerOptions, AIFunctionDeclaration.JsonSchema, AIFunctionDeclaration.ReturnJsonSchema, AITool.ToString(), AITool.GetService(Type, object?), AITool.GetService<TService>(object?), AITool.Name, AITool.Description, AITool.AdditionalProperties, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Installed by ToolWrapperChain.Compose one layer inside the authorization wrapper and outside the timeout wrapper: a caller who cannot make the call at all is turned away before its arguments are even inspected, and a malformed call never consumes a timeout budget or waits on a human approval.

A rejection throws TraconException with the validator’s reason as its message. This is the opposite choice from AuthorizingAIFunction, which returns a denial as an ordinary successful result: an authorization denial is a legitimate business outcome, but rejected arguments are a malformed call, and Microsoft Agent Framework’s own conversion of a thrown exception into a FunctionResultContent is what makes the run record it as ToolFailed instead of an ordinary result.

If IToolArgumentsValidator.ValidateAsync throws, the call is rejected (fail-closed) with a generic reason. A gate that fails open on an exception is not a gate.

ValidatingAIFunction(AIFunction, ToolDescriptor, IToolArgumentsValidator, ILogger<ValidatingAIFunction>)

Section titled “ ValidatingAIFunction(AIFunction, ToolDescriptor, IToolArgumentsValidator, ILogger<ValidatingAIFunction>)”

Creates a new argument validation wrapper.

public ValidatingAIFunction(AIFunction innerFunction, ToolDescriptor descriptor, IToolArgumentsValidator validator, ILogger<ValidatingAIFunction> logger)

innerFunction AIFunction

The tool to wrap.

descriptor ToolDescriptor

The tool’s descriptor, passed to the validator.

validator IToolArgumentsValidator

The validation policy.

logger ILogger<ValidatingAIFunction>

The logger for a faulting validator.

InvokeCoreAsync(AIFunctionArguments, CancellationToken)

Section titled “ InvokeCoreAsync(AIFunctionArguments, CancellationToken)”

Invokes the AI.AIFunction and returns its result.

protected override ValueTask<object?> InvokeCoreAsync(AIFunctionArguments arguments, CancellationToken cancellationToken)

arguments AIFunctionArguments

The arguments to pass to the function’s invocation.

cancellationToken CancellationToken

The CancellationToken to monitor for cancellation requests.

ValueTask<object?>

The result of the function’s execution.