microsoft/semantic-kernel · error · KernelException

`Default` handlers must not have an eval expression.

Error message

`Default` handlers must not have an eval expression.

What it means

Thrown by DeclarativeEventHandlerGroupBuilder constructor when a condition of type Default has a non-whitespace Expression property. Default conditions are unconditional fallbacks — supplying an eval expression to a Default handler is contradictory by design.

Source

Thrown at dotnet/src/Experimental/Process.Core/ProcessAgentBuilder.cs:288

        if (conditions is not null)
        {
            foreach (var condition in conditions)
            {
                if (condition is null)
                {
                    continue;
                }

                if (condition.Type == DeclarativeProcessConditionType.Default)
                {
                    if (this.DefaultHandler is not null)
                    {
                        throw new KernelException("Only one `Default` handler is allowed in a group of event handlers.");
                    }

                    if (!string.IsNullOrWhiteSpace(condition.Expression))
                    {
                        throw new KernelException("`Default` handlers must not have an eval expression.");
                    }

                    this.DefaultHandler = new DeclarativeEventHandlerBuilder(condition);
                }
                else if (condition.Type == DeclarativeProcessConditionType.Eval)
                {
                    this.EvalHandlers ??= [];
                    this.EvalHandlers.Add(new DeclarativeEventHandlerBuilder(condition));
                }
                else if (condition.Type == DeclarativeProcessConditionType.Always)
                {
                    if (this.DefaultHandler is not null)
                    {
                        throw new KernelException("Only one `Always` handler is allowed in a group of event handlers.");
                    }

                    if (!string.IsNullOrWhiteSpace(condition.Expression))
                    {

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Remove the Expression property from any condition with Type == Default.
  2. If the expression is meaningful, change the condition Type to Eval instead of Default.
  3. Validate that Default conditions have null or whitespace Expression before building the handler group.

Example fix

// before
var condition = new DeclarativeProcessCondition
{
    Type = DeclarativeProcessConditionType.Default,
    Expression = "$.status == 'ok'" // not allowed — throws
};

// after
var condition = new DeclarativeProcessCondition
{
    Type = DeclarativeProcessConditionType.Default // no expression
};
Defensive patterns

Strategy: validation

Validate before calling

public static void ValidateDefaultCondition(DeclarativeProcessCondition condition)
{
    if (condition.Type == DeclarativeProcessConditionType.Default
        && !string.IsNullOrWhiteSpace(condition.Expression))
    {
        throw new KernelException("Default conditions must not have an eval expression.");
    }
}

Prevention

When it happens

Trigger: Creating a DeclarativeProcessCondition with Type == Default and a non-empty Expression string, then passing it to OnComplete or OnError. This can happen when authoring declarative YAML with a 'default' handler that also has an 'expression' field.

Common situations: Authoring declarative agent handler YAML/JSON where a 'default' case erroneously includes an eval expression. Copying an Eval handler definition and changing only the type to Default without clearing the expression. Deserialization of malformed condition data.

Related errors


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