Method EnsureValid
EnsureValid(ToolCallPolicy)
Validates the registry contents and (optionally) a ToolCallPolicy configuration before prompting a model or attempting tool invocation.
public void EnsureValid(ToolCallPolicy toolCallPolicy = null)
Parameters
toolCallPolicy
ToolCallPolicyPolicy to validate against the registry. May be
null
to validate tools only.
Remarks
Registry validation
Ensures each registered tool is non-null, has a non-empty Name, matches its dictionary key exactly (ordinal),
and provides a valid input schema (see ValidateSchemaOrThrow(string, string)).
Policy validation
When toolCallPolicy
is provided:
- MaxCallsPerTurn must be >= 0.
- If Choice is Required, at least one tool must be registered.
- If Choice is Specific, ForcedToolName must be non-empty and present in the registry.
Exceptions
- InvalidOperationException
Thrown when the registry or policy is in an invalid state (e.g., null entries, name/key mismatch, missing required tools, invalid tool input schemas, or Specific without a matching tool).
- ArgumentOutOfRangeException
Thrown when MaxCallsPerTurn is negative.