microsoft/semantic-kernel · error · NotSupportedException

Argument '{propertyName}' has a value that doesn't support a

Error message

Argument '{propertyName}' has a value that doesn't support automatic encoding. Set {nameof(InputVariable.AllowDangerouslySetContent)} to 'true' for this argument and implement custom encoding, or provide the value as a string.

What it means

Thrown by LiquidPromptTemplate's value-encoding path when an input variable's value is a complex type that is neither a string nor a type whitelisted by `IsSafeType`, and the argument's `AllowDangerouslySetContent` is false. Liquid encodes safe primitives automatically; for arbitrary objects it refuses to silently stringify potentially dangerous content and instead requires the caller to opt into raw injection.

Source

Thrown at dotnet/src/Extensions/PromptTemplates.Liquid/LiquidPromptTemplate.cs:234

        }

        var valueType = propertyValue.GetType();

        var underlyingType = Nullable.GetUnderlyingType(valueType) ?? valueType;

        if (underlyingType == typeof(string))
        {
            var stringValue = (string)propertyValue;
            return stringValue.Replace(ColonString, ReservedString);
        }

        if (this.IsSafeType(underlyingType))
        {
            return propertyValue;
        }

        // For complex types, throw an exception if dangerous content is not allowed
        throw new NotSupportedException(
            $"Argument '{propertyName}' has a value that doesn't support automatic encoding. " +
            $"Set {nameof(InputVariable.AllowDangerouslySetContent)} to 'true' for this argument and implement custom encoding, " +
            "or provide the value as a string.");
    }

    /// <summary>
    /// Determines if a type is considered safe and doesn't require encoding.
    /// </summary>
    /// <param name="type">The type to check.</param>
    /// <returns>True if the type is safe, false otherwise.</returns>
    private bool IsSafeType(Type type)
    {
        return type == typeof(byte) ||
               type == typeof(sbyte) ||
               type == typeof(bool) ||
               type == typeof(ushort) ||
               type == typeof(short) ||
               type == typeof(char) ||

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Serialize the value to a string before passing it into KernelArguments.
  2. Set `InputVariable.AllowDangerouslySetContent = true` on that variable AND implement your own sanitization.
  3. Restructure the input so only primitive/safe-typed values reach the template.

Example fix

// before
arguments["user"] = myUserObject; // complex type
// after
arguments["user"] = JsonSerializer.Serialize(myUserObject);
Defensive patterns

Strategy: validation

Validate before calling

// Stringify complex values before adding them to KernelArguments:
foreach (var k in arguments.Names) {
    var v = arguments[k];
    if (v is not string && v is not null && !IsPrimitive(v.GetType())) {
        arguments[k] = JsonSerializer.Serialize(v);
    }
}

Prevention

When it happens

Trigger: Passing an object/struct/dictionary as an input variable value (e.g. a POCO, a JObject, a List<T>) where the corresponding InputVariable.AllowDangerouslySetContent is false.

Common situations: Binding a domain model directly into a prompt instead of pre-serializing to a string; upgrading a variable from string to object without updating InputVariables config.

Related errors


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