LykosAI/StabilityMatrix · error · InvalidOperationException

Expected network weight.

Error message

Expected network weight.

What it means

Thrown by ParseNetwork when parsing the optional model weight: after a second ':' the parser consumes a token that must be scoped 'constant.numeric'. If the token is missing or not numeric, it throws 'Expected network weight.' This covers the first (model) weight slot in '<lora:name:0.8:0.6>'.

Solutions

  1. Supply a numeric weight: '<lora:name:0.8>'
  2. Use '.' as the decimal separator, not ','
  3. Omit the second colon entirely if no weight is intended: '<lora:name>'
  4. Catch InvalidOperationException and validate tag weights before parsing

Example fix

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

Strategy: validation

Validate before calling

bool HasNumericWeights(string tag) { var m = System.Text.RegularExpressions.Regex.Matches(tag, ":([0-9]*\.?[0-9]+)"); return m.Count > 0; } // all weight slots are ASCII decimals

Type guard

null

Try / catch

try { var node = builder.Parse(prompt); } catch (InvalidOperationException ex) when (ex.Message.Contains("network weight")) { // prompt user to fix the weight value }

Prevention

When it happens

Trigger: Input like '<lora:name:abc>' where the model weight is non-numeric, or '<lora:name:>' where the weight is absent after the second colon.

Common situations: Weights written as text ('strong', 'high') instead of numbers; locale-formatted decimals with commas ('0,8'); truncated tags where the numeric part was cut off.

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

Appendix: source

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

        var nameToken = PeekToken();
        if (nameToken is null || !nameToken.Scopes.Contains("meta.embedded.network.model.prompt"))
            throw new InvalidOperationException("Expected network name.");
        var name = ParseText();

        // model weight, clip weight
        NumberNode? modelWeight = null;
        NumberNode? clipWeight = null;

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

            // Parse the model weight.
            var modelWeightToken = ConsumeToken();
            if (modelWeightToken is null || !modelWeightToken.Scopes.Contains("constant.numeric"))
                throw new InvalidOperationException("Expected network weight.");
            modelWeight = ParseNumber();

            // colon
            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 (

View on GitHub (pinned to af93d6ef57)