microsoft/semantic-kernel · error · ArgumentException

Invalid execution settings, cannot convert to {nameof(AzureA

Error message

Invalid execution settings, cannot convert to {nameof(AzureAIInferencePromptExecutionSettings)}

What it means

Thrown by AzureAIInferencePromptExecutionSettings.FromExecutionSettings when an incoming PromptExecutionSettings cannot be converted. Conversion first short-circuits for null and same-type inputs, then serializes the object to JSON and deserializes into AzureAIInferencePromptExecutionSettings using JsonOptionsCache.ReadPermissive. If that deserialization yields null, an ArgumentException is thrown.

Source

Thrown at dotnet/src/Connectors/Connectors.AzureAIInference/Settings/AzureAIInferencePromptExecutionSettings.cs:264

        if (executionSettings is null)
        {
            return new AzureAIInferencePromptExecutionSettings();
        }

        if (executionSettings is AzureAIInferencePromptExecutionSettings settings)
        {
            return settings;
        }

        var json = JsonSerializer.Serialize(executionSettings);

        var aiInferenceSettings = JsonSerializer.Deserialize<AzureAIInferencePromptExecutionSettings>(json, JsonOptionsCache.ReadPermissive);
        if (aiInferenceSettings is not null)
        {
            return aiInferenceSettings;
        }

        throw new ArgumentException($"Invalid execution settings, cannot convert to {nameof(AzureAIInferencePromptExecutionSettings)}", nameof(executionSettings));
    }

    #region private ================================================================================

    private string? _extraParameters;
    private float? _frequencyPenalty;
    private float? _presencePenalty;
    private float? _temperature;
    private float? _nucleusSamplingFactor;
    private int? _maxTokens;
    private object? _responseFormat;
    private IList<string>? _stopSequences;
    private IList<ChatCompletionsToolDefinition>? _tools;
    private long? _seed;

    #endregion
}

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Construct an AzureAIInferencePromptExecutionSettings directly instead of relying on cross-type conversion.
  2. Ensure the source settings object JSON-serializes to a non-null JSON object with known properties.
  3. If loading from config, validate the settings node exists and is an object before FromExecutionSettings.
  4. Catch ArgumentException around settings conversion and provide a clear configuration error.

Example fix

// before
var settings = PromptExecutionSettings.FromDictionary(configDict);
var azure = AzureAIInferencePromptExecutionSettings.FromExecutionSettings(settings);
// throws if configDict deserializes to null

// after
var azure = new AzureAIInferencePromptExecutionSettings
{
    Temperature = 0.7f,
    MaxTokens = 512
};
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight: ensure the settings JSON is a non-null object
var json = JsonSerializer.Serialize(executionSettings);
using var doc = JsonDocument.Parse(json);
if (doc.RootElement.ValueKind != JsonValueKind.Object)
    throw new ArgumentException("Execution settings must serialize to a JSON object.");
var azure = AzureAIInferencePromptExecutionSettings.FromExecutionSettings(executionSettings);

Type guard

bool IsConvertibleToAzureAI(PromptExecutionSettings? s)
{
    if (s is null || s is AzureAIInferencePromptExecutionSettings) return true;
    var json = JsonSerializer.Serialize(s);
    using var doc = JsonDocument.Parse(json);
    return doc.RootElement.ValueKind == JsonValueKind.Object;
}

Try / catch

try { return AzureAIInferencePromptExecutionSettings.FromExecutionSettings(settings); }
catch (ArgumentException ex) when (ex.Message.Contains("cannot convert to AzureAIInferencePromptExecutionSettings"))
{ throw new ConfigurationException("Execution settings could not be converted to AzureAIInferencePromptExecutionSettings.", ex); }

Prevention

When it happens

Trigger: Passing an execution settings instance whose JSON serialization deserializes to null for AzureAIInferencePromptExecutionSettings — e.g. a malformed ExtensionData, a settings subclass with incompatible constructor/property shapes, or a Dictionary-backed settings whose JSON root is not an object. Also from a config file where the settings node cannot bind.

Common situations: Hand-constructing a PromptExecutionSettings from an anonymous/dictionary object whose JSON form is empty or non-object. Loading settings from YAML/JSON config where the node is missing or null. Passing an OpenAI-specific settings object with fields that fail permissive binding.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/36d27f224ce23b91. Report an issue: GitHub.