LykosAI/StabilityMatrix · error · InvalidOperationException

Expected closing bracket.

Error message

Expected closing bracket.

What it means

Thrown by ParseNetwork at the end of parsing a network directive: the consumed token must close the tag with a '>' scoped as 'punctuation.definition.network.end.prompt'. If it is missing or scoped differently, the parser throws 'Expected closing bracket.' Unlike the weighted-group parser, it checks only the scope, not the literal text.

Solutions

  1. Close every network tag with '>': '<lora:name:0.8>'
  2. Check the tokenizer grammar scopes the closing '>' as punctuation.definition.network.end.prompt
  3. If truncation by prompt-length limits is the cause, trim earlier parts of the prompt instead of the tag
  4. Catch InvalidOperationException and report the unterminated tag position to the user

Example fix

// before
var prompt = "<lora:myModel:0.8";
// after
var prompt = "<lora:myModel:0.8>";
Defensive patterns

Strategy: validation

Validate before calling

bool HasClosingBracket(string tag) { int depth = 0; foreach (var c in tag) { if (c=='<') depth++; else if (c=='>') depth--; if (depth < 0) return false; } return depth == 0; }

Type guard

null

Try / catch

try { var node = builder.Parse(prompt); } catch (InvalidOperationException ex) when (ex.Message.Contains("closing bracket")) { // report unterminated network tag with its start index }

Prevention

When it happens

Trigger: Input like '<lora:name:0.8' with the closing '>' missing, or the '>' tokenized with unexpected scopes (e.g. treated as HTML by the tokenizer grammar), or input truncated before the '>'.

Common situations: LoRA tags truncated by copy/paste or prompt-length limits; text written in editors that escape or split '>'; grammar version mismatches between the tokenizer and PromptSyntaxBuilder scope expectations.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/2a1d29be32e803e5. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Core/Models/PromptSyntax/PromptSyntaxBuilder.cs:295

            nextToken = PeekToken();
            if (nextToken is not null && nextToken.Scopes.Contains("punctuation.separator.variable.prompt"))
            {
                ConsumeToken(); // consume colon

                // Parse the clip weight.
                var clipWeightToken = ConsumeToken();
                if (clipWeightToken is null || !clipWeightToken.Scopes.Contains("constant.numeric"))
                    throw new InvalidOperationException("Expected network weight.");
                clipWeight = ParseNumber();
            }
        }

        var endNetworkToken = ConsumeToken();
        if (
            endNetworkToken is null
            || !endNetworkToken.Scopes.Contains("punctuation.definition.network.end.prompt")
        )
            throw new InvalidOperationException("Expected closing bracket.");

        return new NetworkNode
        {
            Span = TextSpan.FromBounds(beginNetworkToken.StartIndex, endNetworkToken.EndIndex),
            NetworkType = type,
            ModelName = name,
            ModelWeight = modelWeight,
            ClipWeight = clipWeight,
        };
    }

    private ArrayNode ParseArray()
    {
        var openBracket = ConsumeToken();
        if (openBracket is null || !openBracket.Scopes.Contains("punctuation.definition.array.begin.prompt"))
            throw new InvalidOperationException("Expected opening bracket.");

        var node = new ArrayNode

View on GitHub (pinned to af93d6ef57)