{"record":{"id":"18d263cc828313c2","repo":"microsoft/semantic-kernel","slug":"the-option-key-key-is-required-for-a-bedrock-f","errorCode":null,"errorMessage":"The option key '{key}' is required for a Bedrock function parameter.","messagePattern":"The option key '(.+?)' is required for a Bedrock function parameter\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Bedrock/Extensions/BedrockAgentToolDefinitionExtensions.cs","lineNumber":49,"sourceCode":"\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    }\n\n    #region private\n    private static string GetRequiredValue(this Dictionary<object, object> parameter, string key)\n    {\n        return parameter.TryGetValue(key, out var requiredValue) && requiredValue is string requiredString\n            ? requiredString\n            : throw new ArgumentException($\"The option key '{key}' is required for a Bedrock function parameter.\");\n    }\n    #endregion\n}\n","sourceCodeStart":31,"sourceCodeEnd":53,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Bedrock/Extensions/BedrockAgentToolDefinitionExtensions.cs#L31-L53","documentation":"Thrown by GetRequiredValue when a Bedrock function parameter dictionary is missing one of the required string keys ('name', 'type', 'description', 'required') or the value is present but not a string. The message includes the missing key name so the caller knows exactly which field is deficient. Each of the four fields is mandatory for Bedrock ParameterDetail.","triggerScenarios":"Registering a tool parameter dictionary that omits one of the required keys (e.g., no 'required' key), or provides a non-string value for one of them (e.g., a boolean true instead of the string \"true\", or an integer for 'type').","commonSituations":"Typo in a key name (e.g., 'require' instead of 'required'); passing a C# bool for 'required' instead of the string \"true\"/\"false\"; omitting 'description'; deserialization that dropped a null for a required field.","solutions":["Ensure every parameter dictionary includes all four keys: 'name', 'type', 'description', 'required', each with a non-null string value.","For 'required', pass the string \"true\" or \"false\" (case-insensitive), not a boolean.","Add a validation helper that checks all four keys exist and are strings before calling CreateParameterDetails.","If loading from JSON, validate the schema rejects missing/null required fields."],"exampleFix":"// before\nnew Dictionary<object,object> { [\"name\"]=\"foo\", [\"type\"]=\"string\", [\"description\"]=\"d\" } // missing 'required'\n\n// after\nnew Dictionary<object,object> { [\"name\"]=\"foo\", [\"type\"]=\"string\", [\"description\"]=\"d\", [\"required\"]=\"true\" }","handlingStrategy":"validation","validationCode":"static readonly string[] RequiredKeys = { \"name\", \"type\", \"description\", \"required\" };\nforeach (var p in parameters.Cast<Dictionary<object, object>>())\n{\n    foreach (var key in RequiredKeys)\n        if (!p.TryGetValue(key, out var v) || v is not string || string.IsNullOrEmpty((string)v))\n            throw new InvalidOperationException($\"Missing or non-string key '{key}' in tool parameter.\");\n}","typeGuard":"static bool HasAllRequiredBedrockKeys(Dictionary<object, object> p) =>\n    new[] { \"name\", \"type\", \"description\", \"required\" }.All(k =>\n        p.TryGetValue(k, out var v) && v is string s && !string.IsNullOrEmpty(s));","tryCatchPattern":"try { var details = def.CreateParameterDetails(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"is required for a Bedrock function parameter\"))\n{\n    logger.LogError(\"Tool parameter missing a required key. Ensure name/type/description/required (all strings).\");\n    throw;\n}","preventionTips":["Always include name, type, description, and required as string values in each parameter dictionary.","Pass 'required' as the string \"true\"/\"false\", not a boolean.","Validate parameter dictionaries with a helper 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"}