LykosAI/StabilityMatrix · error · InvalidOperationException

Unexpected end of input.

Error message

Unexpected end of input.

What it means

Thrown by ParseParenthesized in PromptSyntaxBuilder when the token stream ends before a parenthesized/weighted prompt group can be parsed and the node has no span length. The parser is driven by textmate scopes, so it only throws this when PeekToken() returns null (no more tokens) while parsing the inside of a '(' group. It is an internal InvalidOperationException, not a checked exception type.

Solutions

  1. Close all open parentheses in the prompt text so the token stream contains the closing ')' after the weight
  2. Ensure weighted syntax is complete: '(text:1.2)' rather than '(text:'
  3. If building prompts programmatically, validate balanced parentheses before calling the parser
  4. Catch InvalidOperationException from Parse and surface a 'malformed prompt syntax' message to the user

Example fix

// before
var prompt = "(detailed face:";
var node = builder.Parse(prompt);
// after
var prompt = "(detailed face:1.2)";
var node = builder.Parse(prompt);
Defensive patterns

Strategy: validation

Validate before calling

bool HasBalancedParens(string prompt) { int depth = 0; foreach (var c in prompt) { 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) { // surface ex.Message as malformed prompt syntax to the user }

Prevention

When it happens

Trigger: Calling ParseNode/Parse on a prompt string whose text ends right after an opening '(' or a '<' weight separator with nothing (or no further tokens) following, e.g. input like "(masterpiece:" or a trailing '(' with no closing tokens.

Common situations: Users paste truncated prompts into A1111-compatible prompt fields; prompt-generation code builds strings programmatically and drops the closing parenthesis; weights written as '(word:' without the trailing number and ')'.

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/9b4069e74b5807fc. Report an issue: GitHub.

Appendix: source

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

    {
        var openParenToken = ConsumeToken(); // Consume the '('
        if (
            openParenToken is null
            || !openParenToken.Scopes.Contains("punctuation.definition.array.begin.prompt")
        )
            throw new InvalidOperationException("Expected opening parenthesis.");

        // Set start index
        var node = new ParenthesizedNode { Span = new TextSpan(openParenToken.StartIndex, 0) };

        while (MoreTokens())
        {
            // Check if no more tokens to consume.
            if (PeekToken() is not { } nextToken)
            {
                // Ensure we have length set
                if (node.Span.Length == 0)
                    throw new InvalidOperationException("Unexpected end of input.");
                break;
            }

            if (nextToken.Scopes.Contains("punctuation.separator.weight.prompt"))
            {
                // Parse the weight.
                ConsumeToken(); // Consume the ':'

                // Check the weight value token.
                var weightToken = PeekToken();
                if (weightToken is null || !weightToken.Scopes.Contains("constant.numeric"))
                {
                    throw new InvalidOperationException("Expected numeric weight value.");
                }

                // Consume the weight token.
                node.Weight = ParseNumber();
            }

View on GitHub (pinned to af93d6ef57)