{"record":{"id":"d673f74c98404e91","repo":"microsoft/semantic-kernel","slug":"always-handlers-must-not-have-an-eval-expression","errorCode":null,"errorMessage":"`Always` handlers must not have an eval expression.","messagePattern":"`Always` handlers must not have an eval expression\\.","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Experimental/Process.Core/ProcessAgentBuilder.cs","lineNumber":307,"sourceCode":"                    }\n\n                    this.DefaultHandler = new DeclarativeEventHandlerBuilder(condition);\n                }\n                else if (condition.Type == DeclarativeProcessConditionType.Eval)\n                {\n                    this.EvalHandlers ??= [];\n                    this.EvalHandlers.Add(new DeclarativeEventHandlerBuilder(condition));\n                }\n                else if (condition.Type == DeclarativeProcessConditionType.Always)\n                {\n                    if (this.DefaultHandler is not null)\n                    {\n                        throw new KernelException(\"Only one `Always` handler is allowed in a group of event handlers.\");\n                    }\n\n                    if (!string.IsNullOrWhiteSpace(condition.Expression))\n                    {\n                        throw new KernelException(\"`Always` handlers must not have an eval expression.\");\n                    }\n\n                    this.AlwaysHandler = new DeclarativeEventHandlerBuilder(condition);\n                }\n                else\n                {\n                    throw new KernelException($\"Unknown condition type: {condition.Type}\");\n                }\n            }\n        }\n    }\n\n    /// <summary>\n    /// The list of semantic handlers for this group of event handlers.\n    /// </summary>\n    public DeclarativeEventHandlerBuilder? AlwaysHandler { get; init; }\n\n    /// <summary>","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Experimental/Process.Core/ProcessAgentBuilder.cs#L289-L325","documentation":"Thrown by DeclarativeEventHandlerGroupBuilder constructor when a condition of type Always has a non-whitespace Expression property. Always conditions are unconditional — they fire on every event regardless of state, so an eval expression is contradictory.","triggerScenarios":"Creating a DeclarativeProcessCondition with Type == Always and a non-empty Expression string. This can arise from YAML/JSON configuration where an 'always' handler mistakenly includes an expression block.","commonSituations":"Authoring declarative handler definitions where an 'always' case accidentally carries an expression from a template or copied Eval handler. Deserialization of condition data that populates Expression for all types regardless of condition type.","solutions":["Remove the Expression property from any condition with Type == Always.","If the expression is meaningful, change the condition Type to Eval.","Validate that Always conditions have null or whitespace Expression before building."],"exampleFix":"// before\nvar condition = new DeclarativeProcessCondition\n{\n    Type = DeclarativeProcessConditionType.Always,\n    Expression = \"$.retry < 3\" // not allowed — throws\n};\n\n// after\nvar condition = new DeclarativeProcessCondition\n{\n    Type = DeclarativeProcessConditionType.Always // no expression\n};","handlingStrategy":"validation","validationCode":"public static void ValidateAlwaysNoExpression(DeclarativeProcessCondition condition)\n{\n    if (condition.Type == DeclarativeProcessConditionType.Always\n        && !string.IsNullOrWhiteSpace(condition.Expression))\n    {\n        throw new KernelException(\"Always conditions must not have an eval expression.\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set Expression on Always-type conditions.","If an expression is needed, use Eval type instead.","Validate declarative YAML to ensure 'always' handlers have no 'expression' field."],"tags":["semantic-kernel","process-framework","declarative","event-handlers","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}