{"record":{"id":"0c12f110a10c5655","repo":"microsoft/semantic-kernel","slug":"invalid-parameter-type-for-function-agenttooldefi","errorCode":null,"errorMessage":"Invalid parameter type for function {agentToolDefinition.Id}","messagePattern":"Invalid parameter type for function (.+?)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Bedrock/Extensions/BedrockAgentToolDefinitionExtensions.cs","lineNumber":24,"sourceCode":"namespace Microsoft.SemanticKernel.Agents.Bedrock;\n\n/// <summary>\n/// Provides extension methods for <see cref=\"AgentToolDefinition\"/>.\n/// </summary>\ninternal static class BedrockAgentToolDefinitionExtensions\n{\n    internal static Dictionary<string, Amazon.BedrockAgent.Model.ParameterDetail> CreateParameterDetails(\n        this AgentToolDefinition agentToolDefinition)\n    {\n        Dictionary<string, Amazon.BedrockAgent.Model.ParameterDetail> parameterSpec = [];\n        var parameters = agentToolDefinition.GetOption<List<object>?>(\"parameters\");\n        if (parameters is not null)\n        {\n            foreach (var parameter in parameters)\n            {\n                if (parameter is not Dictionary<object, object> parameterDict)\n                {\n                    throw new ArgumentException($\"Invalid parameter type for function {agentToolDefinition.Id}\");\n                }\n\n                var name = parameterDict.GetRequiredValue(\"name\");\n                var type = parameterDict.GetRequiredValue(\"type\");\n                var description = parameterDict.GetRequiredValue(\"description\");\n                var isRequired = parameterDict.GetRequiredValue(\"required\").Equals(\"true\", StringComparison.OrdinalIgnoreCase);\n\n                parameterSpec.Add(name, new Amazon.BedrockAgent.Model.ParameterDetail\n                {\n                    Description = description,\n                    Required = isRequired,\n                    Type = new Amazon.BedrockAgent.Type(type),\n                });\n            }\n        }\n\n        return parameterSpec;\n    }","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Bedrock/Extensions/BedrockAgentToolDefinitionExtensions.cs#L6-L42","documentation":"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.","triggerScenarios":"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>.","commonSituations":"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.","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."],"exampleFix":"// before\nvar def = new AgentToolDefinition(\"myTool\");\ndef.SetOption(\"parameters\", new List<object> { \"name=foo\" /* wrong type */ });\n\n// after\ndef.SetOption(\"parameters\", new List<object>\n{\n    new Dictionary<object,object>\n    {\n        [\"name\"] = \"foo\", [\"type\"] = \"string\", [\"description\"] = \"a param\", [\"required\"] = \"true\"\n    }\n});","handlingStrategy":"validation","validationCode":"List<object> parameters = def.GetOption<List<object>?>(\"parameters\") ?? new();\nforeach (var p in parameters)\n{\n    if (p is not Dictionary<object, object>)\n        throw new InvalidOperationException($\"Tool parameter is not a dictionary: {p}\");\n}\n// then call CreateParameterDetails","typeGuard":"static bool IsValidBedrockParameter(object p) => p is Dictionary<object, object>;","tryCatchPattern":"try { var details = def.CreateParameterDetails(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid parameter type\"))\n{\n    logger.LogError(\"Tool parameter entry is not a Dictionary<object,object>. Fix the parameters option.\");\n    throw;\n}","preventionTips":["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."],"tags":["bedrock","agents","tool-definition","validation","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}