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
- Ensure each parameter entry in the 'parameters' option is a Dictionary<object, object> with string keys 'name', 'type', 'description', 'required'.
- If building from JSON, deserialize into Dictionary<object,object> (or convert Dictionary<string,object> entries before passing).
- Validate the parameter list shape in a unit test before agent creation.
- 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
- Build tool parameters as List<Dictionary<object,object>> with string keys.
- If loading from JSON, deserialize and convert to Dictionary<object,object> before SetOption.
- Add a unit test that validates every tool parameter is a dictionary before agent creation.
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
- The option key '{key}' is required for a Bedrock function pa
- Unsupported parameter type: {typeString}
- Message role must be either Assistant or User.
- No function results were returned.
- runtimeClient
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/0c12f110a10c5655.
Report an issue: GitHub.