microsoft/semantic-kernel · error · ArgumentException

The option key ' ' is required for a Bedrock function…

Error message

The option key '{key}' is required for a Bedrock function parameter.

What it means

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.

Solutions

  1. Ensure every parameter dictionary includes all four keys: 'name', 'type', 'description', 'required', each with a non-null string value.
  2. For 'required', pass the string "true" or "false" (case-insensitive), not a boolean.
  3. Add a validation helper that checks all four keys exist and are strings before calling CreateParameterDetails.
  4. If loading from JSON, validate the schema rejects missing/null required fields.

Example fix

// before
new Dictionary<object,object> { ["name"]="foo", ["type"]="string", ["description"]="d" } // missing 'required'

// after
new Dictionary<object,object> { ["name"]="foo", ["type"]="string", ["description"]="d", ["required"]="true" }
Defensive patterns

Strategy: validation

Validate before calling

static readonly string[] RequiredKeys = { "name", "type", "description", "required" };
foreach (var p in parameters.Cast<Dictionary<object, object>>())
{
    foreach (var key in RequiredKeys)
        if (!p.TryGetValue(key, out var v) || v is not string || string.IsNullOrEmpty((string)v))
            throw new InvalidOperationException($"Missing or non-string key '{key}' in tool parameter.");
}

Type guard

static bool HasAllRequiredBedrockKeys(Dictionary<object, object> p) =>
    new[] { "name", "type", "description", "required" }.All(k =>
        p.TryGetValue(k, out var v) && v is string s && !string.IsNullOrEmpty(s));

Try / catch

try { var details = def.CreateParameterDetails(); }
catch (ArgumentException ex) when (ex.Message.Contains("is required for a Bedrock function parameter"))
{
    logger.LogError("Tool parameter missing a required key. Ensure name/type/description/required (all strings).");
    throw;
}

Prevention

When it happens

Trigger: 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').

Common situations: 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.

Related errors


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

Appendix: source

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

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

        return parameterSpec;
    }

    #region private
    private static string GetRequiredValue(this Dictionary<object, object> parameter, string key)
    {
        return parameter.TryGetValue(key, out var requiredValue) && requiredValue is string requiredString
            ? requiredString
            : throw new ArgumentException($"The option key '{key}' is required for a Bedrock function parameter.");
    }
    #endregion
}

View on GitHub (pinned to c028a0c7dc)