{"record":{"id":"f159d000f89dd65c","repo":"microsoft/semantic-kernel","slug":"the-option-keys-name-and-type-are-required-for","errorCode":null,"errorMessage":"The option keys 'name' and 'type' are required for a parameter.","messagePattern":"The option keys 'name' and 'type' are required for a parameter\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/AzureAI/Extensions/AgentToolDefinitionExtensions.cs","lineNumber":46,"sourceCode":"        return parameters is not null ? CreateParameterSpec(parameters) : s_noParams;\n    }\n\n    internal static BinaryData CreateParameterSpec(List<object> parameters)\n    {\n        JsonSchemaFunctionParameters parameterSpec = new();\n        foreach (var parameter in parameters)\n        {\n            var parameterProps = parameter as Dictionary<object, object>;\n            if (parameterProps is not null)\n            {\n                bool isRequired = parameterProps.TryGetValue(\"required\", out var requiredValue) && requiredValue is string requiredString && requiredString.Equals(\"true\", StringComparison.OrdinalIgnoreCase);\n                string? name = parameterProps.TryGetValue(\"name\", out var nameValue) && nameValue is string nameString ? nameString : null;\n                string? type = parameterProps.TryGetValue(\"type\", out var typeValue) && typeValue is string typeString ? typeString : null;\n                string? description = parameterProps.TryGetValue(\"description\", out var descriptionValue) && descriptionValue is string descriptionString ? descriptionString : string.Empty;\n\n                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(type))\n                {\n                    throw new ArgumentException(\"The option keys 'name' and 'type' are required for a parameter.\");\n                }\n\n                if (isRequired)\n                {\n                    parameterSpec.Required.Add(name!);\n                }\n                parameterSpec.Properties.Add(name!, KernelJsonSchema.Parse($\"{{ \\\"type\\\": \\\"{type}\\\", \\\"description\\\": \\\"{description}\\\" }}\"));\n            }\n        }\n\n        return BinaryData.FromObjectAsJson(parameterSpec);\n    }\n\n    internal static FileSearchToolDefinitionDetails GetFileSearchToolDefinitionDetails(this AgentToolDefinition agentToolDefinition)\n    {\n        var details = new FileSearchToolDefinitionDetails();\n        var maxNumResults = agentToolDefinition.GetOption<int?>(\"max_num_results\");\n        if (maxNumResults is not null and > 0)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/AzureAI/Extensions/AgentToolDefinitionExtensions.cs#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"Malformed agent definition parameter list. A numeric or boolean value supplied where a type string is expected. Parameter dict missing the 'type' key.","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\"."],"exampleFix":"// before\nparameters:\n  - name: query\n    # type missing -> throws 162\n\n// after\nparameters:\n  - name: query\n    type: string\n    description: The search query","handlingStrategy":"validation","validationCode":"foreach (var p in parameters)\n{\n    if (p is not Dictionary<object, object> d) continue;\n    bool hasName = d.TryGetValue(\"name\", out var n) && n is string s1 && !string.IsNullOrEmpty(s1);\n    bool hasType = d.TryGetValue(\"type\", out var ty) && ty is string s2 && !string.IsNullOrEmpty(s2);\n    if (!hasName || !hasType) throw new ArgumentException(\"Each parameter needs non-empty 'name' and 'type' strings.\");\n}","typeGuard":"static bool IsValidParameter(Dictionary<object, object> p) =>\n    p.TryGetValue(\"name\", out var n) && n is string sn && !string.IsNullOrEmpty(sn)\n    && p.TryGetValue(\"type\", out var t) && t is string st && !string.IsNullOrEmpty(st);","tryCatchPattern":"try { var data = tool.CreateFunctionParameters(parameters); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"'name' and 'type'\"))\n{ /* surface a friendly validation error to the config author */ }","preventionTips":["Always specify 'name' and 'type' (as strings) for every parameter in tool definitions.","Use a linter/schema validator for agent definition files."],"tags":["validation","agent-tool","function","json-schema"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}