{"record":{"id":"7fdddaa7862f1619","repo":"microsoft/semantic-kernel","slug":"the-maximum-indentation-level-must-be-at-least-1","errorCode":null,"errorMessage":"The maximum indentation level must be at least 1.","messagePattern":"The maximum indentation level must be at least 1\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Experimental/Process.Core/Tools/ProcessVisualizationExtensions.cs","lineNumber":37,"sourceCode":"    /// <returns></returns>\n    public static string ToMermaid(this ProcessBuilder processBuilder, int maxLevel = 2)\n    {\n        var process = processBuilder.Build();\n        return process.ToMermaid(maxLevel);\n    }\n\n    /// <summary>\n    /// Generates a Mermaid diagram from a kernel process.\n    /// </summary>\n    /// <param name=\"process\"></param>\n    /// <param name=\"maxLevel\">The maximum indentation level to reach for nested processes, 1 is basically no nesting</param>\n    /// <returns></returns>\n    public static string ToMermaid(this KernelProcess process, int maxLevel = 2)\n    {\n        // Check that the maximum level is at least 1\n        if (maxLevel < 1)\n        {\n            throw new InvalidOperationException(\"The maximum indentation level must be at least 1.\");\n        }\n\n        StringBuilder sb = new();\n        sb.AppendLine(\"flowchart LR\");\n\n        // Generate the Mermaid flowchart content with indentation\n        string flowchartContent = RenderProcess(process, 1, isSubProcess: false, maxLevel);\n\n        // Append the formatted content to the main StringBuilder\n        sb.Append(flowchartContent);\n\n        return sb.ToString();\n    }\n\n    /// <summary>\n    /// Renders a process and its nested processes recursively as a Mermaid flowchart.\n    /// </summary>\n    /// <param name=\"process\">The process to render.</param>","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Experimental/Process.Core/Tools/ProcessVisualizationExtensions.cs#L19-L55","documentation":"Thrown by the ToMermaid extension when the maxLevel argument is less than 1. maxLevel controls how deep nested (sub)processes are expanded in the generated flowchart; 1 means no nesting is rendered, and 0 or negatives are invalid.","triggerScenarios":"Calling kernelProcess.ToMermaid(maxLevel) with 0, a negative number, or a value computed from a subtraction that underflows to <=0.","commonSituations":"Computing maxLevel from a depth that can be 0 (e.g. level - 1); passing a config default that was mis-set to 0; defensive code that passes 0 intending 'no limit'.","solutions":["Pass maxLevel >= 1; use 1 to render only the top process with no nested expansion.","Clamp computed values with Math.Max(1, computedLevel) before calling ToMermaid.","Review configuration defaults for the visualization depth to ensure a positive value."],"exampleFix":"// before\nvar diagram = process.ToMermaid(maxLevel: depth - 1); // depth == 1 -> throws\n\n// after\nvar diagram = process.ToMermaid(Math.Max(1, depth - 1));","handlingStrategy":"validation","validationCode":"int safeLevel = Math.Max(1, requestedLevel);\nvar diagram = process.ToMermaid(safeLevel);","typeGuard":"static bool IsValidMaxLevel(int level) => level >= 1;","tryCatchPattern":"try { var d = process.ToMermaid(level); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"indentation level\"))\n{ /* default to 1 or 2 and retry */ }","preventionTips":["Always clamp computed depth values to at least 1.","Treat 0/negative maxLevel as a config error and surface it at config-load time.","Document that 1 means 'top process only, no nesting'."],"tags":["semantic-kernel","process","visualization","mermaid"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}