{"record":{"id":"298aaf8e97922394","repo":"microsoft/semantic-kernel","slug":"parameter-param-name-is-required-for-function-f","errorCode":null,"errorMessage":"Parameter {param.Name} is required for function {functionMetadata.Name}.","messagePattern":"Parameter (.+?) is required for function (.+?)\\.","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Extensions/PromptTemplates.Handlebars/Helpers/KernelHelpers/KernelFunctionHelpers.cs","lineNumber":159,"sourceCode":"        // Prepare the input parameters for the function\n        foreach (var param in functionMetadata.Parameters)\n        {\n            var fullyQualifiedParamName = functionMetadata.Name + nameDelimiter + param.Name;\n            if (handlebarsArguments is not null && (handlebarsArguments.TryGetValue(fullyQualifiedParamName, out var value) || handlebarsArguments.TryGetValue(param.Name, out value)))\n            {\n                value = KernelHelpersUtils.GetArgumentValue(value, executionContext);\n                if (IsExpectedParameterType(param, value))\n                {\n                    executionContext[param.Name] = value;\n                }\n                else\n                {\n                    throw new KernelException($\"Invalid argument type for function {functionMetadata.Name}. Parameter {param.Name} expects type {param.ParameterType ?? (object?)param.Schema} but received {value?.GetType().ToString() ?? \"<null>\"}.\");\n                }\n            }\n            else if (param.IsRequired)\n            {\n                throw new KernelException($\"Parameter {param.Name} is required for function {functionMetadata.Name}.\");\n            }\n        }\n    }\n\n    /// <summary>\n    /// Processes the positional arguments passed to a Handlebars helper function.\n    /// </summary>\n    /// <param name=\"functionMetadata\">KernelFunctionMetadata for the function being invoked.</param>\n    /// <param name=\"executionContext\">Arguments maintained in the executing context.</param>\n    /// <param name=\"handlebarsArguments\">Arguments passed to the Handlebars helper.</param>\n    /// <exception cref=\"KernelException\">Thrown when a required parameter is missing.</exception>\n    private static void ProcessPositionalArguments(KernelFunctionMetadata functionMetadata, KernelArguments executionContext, Arguments handlebarsArguments)\n    {\n        var requiredParameters = functionMetadata.Parameters.Where(p => p.IsRequired).ToList();\n\n        if (requiredParameters.Count <= handlebarsArguments.Length && handlebarsArguments.Length <= functionMetadata.Parameters.Count)\n        {\n            var argIndex = 0;","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Extensions/PromptTemplates.Handlebars/Helpers/KernelHelpers/KernelFunctionHelpers.cs#L141-L177","documentation":"Thrown during hash-argument processing when a required parameter is not present among the supplied arguments. After checking all hash arguments, any remaining required parameter that was not provided triggers this.","triggerScenarios":"ProcessHashArguments iterates functionMetadata.Parameters; if a parameter with IsRequired is not found in handlebarsArguments (neither by fully-qualified nor short name), the exception fires.","commonSituations":"A required parameter was added to the function but the template was not updated, or the parameter name used in the template does not match (fully-qualified vs short name).","solutions":["Add the missing required parameter to the template hash (e.g., {{Function requiredParam=\"value\"}}).","Verify the parameter name spelling matches the function metadata exactly.","Mark the parameter IsRequired=false if it is genuinely optional."],"exampleFix":"// before\n{{Plugin-Function optionalArg=\"x\"}}\n// after (requiredArg is required)\n{{Plugin-Function requiredArg=\"y\" optionalArg=\"x\"}}","handlingStrategy":"validation","validationCode":"var missing = functionMetadata.Parameters\n    .Where(p => p.IsRequired && !handlebarsArguments.ContainsKey(p.Name))\n    .Select(p => p.Name).ToList();\nif (missing.Count > 0)\n    throw new InvalidOperationException($\"Missing required params: {string.Join(\", \", missing)}\");","typeGuard":"public static bool HasRequiredHashArgs(KernelFunctionMetadata meta, IDictionary<string, object> args) =>\n    meta.Parameters.Where(p => p.IsRequired).All(p => args.ContainsKey(p.Name));","tryCatchPattern":"try\n{\n    var result = await template.RenderAsync(kernel, arguments).ConfigureAwait(false);\n}\ncatch (KernelException ex) when (ex.Message.Contains(\"is required for function\"))\n{\n    _logger.LogError(ex, \"Template missing a required parameter; add it to the hash args.\");\n    throw;\n}","preventionTips":["Cross-check required parameters when writing template function calls.","Keep templates updated after adding required parameters to functions.","Validate templates against metadata in CI."],"tags":["handlebars","prompt-templates","function-invocation","missing-parameter","arguments"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}