microsoft/semantic-kernel · error · KernelException

Parameter {param.Name} is required for function {functionMet

Error message

Parameter {param.Name} is required for function {functionMetadata.Name}.

What it means

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.

Source

Thrown at dotnet/src/Extensions/PromptTemplates.Handlebars/Helpers/KernelHelpers/KernelFunctionHelpers.cs:159

        // Prepare the input parameters for the function
        foreach (var param in functionMetadata.Parameters)
        {
            var fullyQualifiedParamName = functionMetadata.Name + nameDelimiter + param.Name;
            if (handlebarsArguments is not null && (handlebarsArguments.TryGetValue(fullyQualifiedParamName, out var value) || handlebarsArguments.TryGetValue(param.Name, out value)))
            {
                value = KernelHelpersUtils.GetArgumentValue(value, executionContext);
                if (IsExpectedParameterType(param, value))
                {
                    executionContext[param.Name] = value;
                }
                else
                {
                    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>"}.");
                }
            }
            else if (param.IsRequired)
            {
                throw new KernelException($"Parameter {param.Name} is required for function {functionMetadata.Name}.");
            }
        }
    }

    /// <summary>
    /// Processes the positional arguments passed to a Handlebars helper function.
    /// </summary>
    /// <param name="functionMetadata">KernelFunctionMetadata for the function being invoked.</param>
    /// <param name="executionContext">Arguments maintained in the executing context.</param>
    /// <param name="handlebarsArguments">Arguments passed to the Handlebars helper.</param>
    /// <exception cref="KernelException">Thrown when a required parameter is missing.</exception>
    private static void ProcessPositionalArguments(KernelFunctionMetadata functionMetadata, KernelArguments executionContext, Arguments handlebarsArguments)
    {
        var requiredParameters = functionMetadata.Parameters.Where(p => p.IsRequired).ToList();

        if (requiredParameters.Count <= handlebarsArguments.Length && handlebarsArguments.Length <= functionMetadata.Parameters.Count)
        {
            var argIndex = 0;

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Add the missing required parameter to the template hash (e.g., {{Function requiredParam="value"}}).
  2. Verify the parameter name spelling matches the function metadata exactly.
  3. Mark the parameter IsRequired=false if it is genuinely optional.

Example fix

// before
{{Plugin-Function optionalArg="x"}}
// after (requiredArg is required)
{{Plugin-Function requiredArg="y" optionalArg="x"}}
Defensive patterns

Strategy: validation

Validate before calling

var missing = functionMetadata.Parameters
    .Where(p => p.IsRequired && !handlebarsArguments.ContainsKey(p.Name))
    .Select(p => p.Name).ToList();
if (missing.Count > 0)
    throw new InvalidOperationException($"Missing required params: {string.Join(", ", missing)}");

Type guard

public static bool HasRequiredHashArgs(KernelFunctionMetadata meta, IDictionary<string, object> args) =>
    meta.Parameters.Where(p => p.IsRequired).All(p => args.ContainsKey(p.Name));

Try / catch

try
{
    var result = await template.RenderAsync(kernel, arguments).ConfigureAwait(false);
}
catch (KernelException ex) when (ex.Message.Contains("is required for function"))
{
    _logger.LogError(ex, "Template missing a required parameter; add it to the hash args.");
    throw;
}

Prevention

When it happens

Trigger: ProcessHashArguments iterates functionMetadata.Parameters; if a parameter with IsRequired is not found in handlebarsArguments (neither by fully-qualified nor short name), the exception fires.

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

Related errors


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