microsoft/semantic-kernel · error · ArgumentException
The option keys 'name' and 'type' are required for a paramet
Error message
The option keys 'name' and 'type' are required for a parameter.
What it means
Thrown while serializing function/tool parameters from a loosely-typed dictionary. Each parameter dictionary must contain a non-empty 'name' string and a non-empty 'type' string; these become the JSON schema property name and its type. If either is missing or empty the method cannot build a valid OpenAI function parameter spec, so it throws ArgumentException. 'description' and 'required' are optional.
Source
Thrown at dotnet/src/Agents/AzureAI/Extensions/AgentToolDefinitionExtensions.cs:46
return parameters is not null ? CreateParameterSpec(parameters) : s_noParams;
}
internal static BinaryData CreateParameterSpec(List<object> parameters)
{
JsonSchemaFunctionParameters parameterSpec = new();
foreach (var parameter in parameters)
{
var parameterProps = parameter as Dictionary<object, object>;
if (parameterProps is not null)
{
bool isRequired = parameterProps.TryGetValue("required", out var requiredValue) && requiredValue is string requiredString && requiredString.Equals("true", StringComparison.OrdinalIgnoreCase);
string? name = parameterProps.TryGetValue("name", out var nameValue) && nameValue is string nameString ? nameString : null;
string? type = parameterProps.TryGetValue("type", out var typeValue) && typeValue is string typeString ? typeString : null;
string? description = parameterProps.TryGetValue("description", out var descriptionValue) && descriptionValue is string descriptionString ? descriptionString : string.Empty;
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(type))
{
throw new ArgumentException("The option keys 'name' and 'type' are required for a parameter.");
}
if (isRequired)
{
parameterSpec.Required.Add(name!);
}
parameterSpec.Properties.Add(name!, KernelJsonSchema.Parse($"{{ \"type\": \"{type}\", \"description\": \"{description}\" }}"));
}
}
return BinaryData.FromObjectAsJson(parameterSpec);
}
internal static FileSearchToolDefinitionDetails GetFileSearchToolDefinitionDetails(this AgentToolDefinition agentToolDefinition)
{
var details = new FileSearchToolDefinitionDetails();
var maxNumResults = agentToolDefinition.GetOption<int?>("max_num_results");
if (maxNumResults is not null and > 0)View on GitHub (pinned to c028a0c7dc)
Solutions
- Ensure every parameter object has 'name' (string) and 'type' (string, e.g. "string", "integer", "boolean", "object", "array").
- Make sure the values are JSON strings, not numbers/booleans.
- Optionally add 'description' and 'required': "true".
Example fix
// before
parameters:
- name: query
# type missing -> throws 162
// after
parameters:
- name: query
type: string
description: The search query Defensive patterns
Strategy: validation
Validate before calling
foreach (var p in parameters)
{
if (p is not Dictionary<object, object> d) continue;
bool hasName = d.TryGetValue("name", out var n) && n is string s1 && !string.IsNullOrEmpty(s1);
bool hasType = d.TryGetValue("type", out var ty) && ty is string s2 && !string.IsNullOrEmpty(s2);
if (!hasName || !hasType) throw new ArgumentException("Each parameter needs non-empty 'name' and 'type' strings.");
} Type guard
static bool IsValidParameter(Dictionary<object, object> p) =>
p.TryGetValue("name", out var n) && n is string sn && !string.IsNullOrEmpty(sn)
&& p.TryGetValue("type", out var t) && t is string st && !string.IsNullOrEmpty(st); Try / catch
try { var data = tool.CreateFunctionParameters(parameters); }
catch (ArgumentException ex) when (ex.Message.Contains("'name' and 'type'"))
{ /* surface a friendly validation error to the config author */ } Prevention
- Always specify 'name' and 'type' (as strings) for every parameter in tool definitions.
- Use a linter/schema validator for agent definition files.
When it happens
Trigger: A tool definition's 'parameters' list contains a dictionary entry where TryGetValue('name') is not a string (or absent) or TryGetValue('type') is not a string (or absent). Note the code only accepts string-typed values, so a non-string value also reads as null and triggers this.
Common situations: Malformed agent definition parameter list. A numeric or boolean value supplied where a type string is expected. Parameter dict missing the 'type' key.
Related errors
- Azure AI Search tool definition must have both 'index_connec
- The option keys 'asset_identifiers' and 'asset_type' are req
- The option keys 'store_name' and 'data_sources' are required
- The option key '{bindingType}.storage_service_endpoint' is r
- The option key '{bindingType}.queue_name' is required.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/f159d000f89dd65c.
Report an issue: GitHub.