microsoft/semantic-kernel · error · ArgumentException

Invalid parameter type for function {agentToolDefinition.Id}

Error message

Invalid parameter type for function {agentToolDefinition.Id}

What it means

Thrown when converting an AgentToolDefinition's parameters into Bedrock ParameterDetail objects, if an individual parameter entry is not a Dictionary<object, object>. The parameters option is expected to be a List<object> where each element is a dictionary with name/type/description/required keys. A non-dictionary element indicates malformed tool parameter metadata.

Source

Thrown at dotnet/src/Agents/Bedrock/Extensions/BedrockAgentToolDefinitionExtensions.cs:24

namespace Microsoft.SemanticKernel.Agents.Bedrock;

/// <summary>
/// Provides extension methods for <see cref="AgentToolDefinition"/>.
/// </summary>
internal static class BedrockAgentToolDefinitionExtensions
{
    internal static Dictionary<string, Amazon.BedrockAgent.Model.ParameterDetail> CreateParameterDetails(
        this AgentToolDefinition agentToolDefinition)
    {
        Dictionary<string, Amazon.BedrockAgent.Model.ParameterDetail> parameterSpec = [];
        var parameters = agentToolDefinition.GetOption<List<object>?>("parameters");
        if (parameters is not null)
        {
            foreach (var parameter in parameters)
            {
                if (parameter is not Dictionary<object, object> parameterDict)
                {
                    throw new ArgumentException($"Invalid parameter type for function {agentToolDefinition.Id}");
                }

                var name = parameterDict.GetRequiredValue("name");
                var type = parameterDict.GetRequiredValue("type");
                var description = parameterDict.GetRequiredValue("description");
                var isRequired = parameterDict.GetRequiredValue("required").Equals("true", StringComparison.OrdinalIgnoreCase);

                parameterSpec.Add(name, new Amazon.BedrockAgent.Model.ParameterDetail
                {
                    Description = description,
                    Required = isRequired,
                    Type = new Amazon.BedrockAgent.Type(type),
                });
            }
        }

        return parameterSpec;
    }

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure each parameter entry in the 'parameters' option is a Dictionary<object, object> with string keys 'name', 'type', 'description', 'required'.
  2. If building from JSON, deserialize into Dictionary<object,object> (or convert Dictionary<string,object> entries before passing).
  3. Validate the parameter list shape in a unit test before agent creation.
  4. Avoid mixing types in the parameters list; keep every element a dictionary.

Example fix

// before
var def = new AgentToolDefinition("myTool");
def.SetOption("parameters", new List<object> { "name=foo" /* wrong type */ });

// after
def.SetOption("parameters", new List<object>
{
    new Dictionary<object,object>
    {
        ["name"] = "foo", ["type"] = "string", ["description"] = "a param", ["required"] = "true"
    }
});
Defensive patterns

Strategy: validation

Validate before calling

List<object> parameters = def.GetOption<List<object>?>("parameters") ?? new();
foreach (var p in parameters)
{
    if (p is not Dictionary<object, object>)
        throw new InvalidOperationException($"Tool parameter is not a dictionary: {p}");
}
// then call CreateParameterDetails

Type guard

static bool IsValidBedrockParameter(object p) => p is Dictionary<object, object>;

Try / catch

try { var details = def.CreateParameterDetails(); }
catch (ArgumentException ex) when (ex.Message.Contains("Invalid parameter type"))
{
    logger.LogError("Tool parameter entry is not a Dictionary<object,object>. Fix the parameters option.");
    throw;
}

Prevention

When it happens

Trigger: Registering a Bedrock agent tool via AgentToolDefinition with a 'parameters' option where one or more entries are not dictionaries — e.g., a raw string, a JObject, an anonymous object, or a JSON-deserialized structure that did not land as Dictionary<object,object>.

Common situations: Deserializing tool parameter JSON into the wrong type (e.g., JsonElement or Dictionary<string,object> instead of Dictionary<object,object>); passing anonymous objects; hand-building the list with mixed types; version mismatch in how parameters are shaped.

Related errors


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