LykosAI/StabilityMatrix · error · InvalidOperationException
Expected numeric weight value.
Error message
Expected numeric weight value.
What it means
Thrown by ParseParenthesized when, after consuming the ':' separator inside a weighted group, the next token is missing or does not carry the textmate scope 'constant.numeric'. The library requires the weight after ':' to be tokenized as a number. It surfaces as an InvalidOperationException naming the missing numeric weight.
Solutions
- Add a valid numeric weight after the colon, e.g. '(text:1.1)'
- Remove the ':' if no weight is intended, using plain '(text)' grouping
- Check for stray characters (spaces are fine, commas are not) between ':' and the number
- Catch InvalidOperationException and report the malformed weight to the user
Example fix
// before var prompt = "(highly detailed:)"; // after var prompt = "(highly detailed:1.3)";
Defensive patterns
Strategy: validation
Validate before calling
var ok = System.Text.RegularExpressions.Regex.IsMatch(prompt, "\([^()]*:[0-9]+(\.[0-9]+)?\)"); // each '(text:w)' group has a numeric weight
Type guard
null
Try / catch
try { var node = builder.Parse(prompt); } catch (InvalidOperationException ex) when (ex.Message.Contains("weight")) { // prompt user to fix the weight after ':' } Prevention
- Always write weights as '(text:1.2)' with ASCII digits and '.' decimals
- Strip or normalize non-numeric characters after ':' before parsing
- Lint prompts from external tools before ingestion
- Provide auto-completion that inserts complete weighted groups
When it happens
Trigger: Parsing input like '(text:)' with an empty weight, or '(text:abc)' where the text after ':' is not tokenized as numeric, or input ending immediately after ':'.
Common situations: Hand-edited prompts where the weight number was deleted or replaced by text ('strong'); locales/tools writing weights with non-ASCII digits or commas ('1,2') that fail to tokenize as numeric.
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
- Expected network weight.
- Unexpected end of input.
- Expected closing parenthesis.
- Expected opening bracket.
- Expected network type.
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/5d8f30313d1fb7f5.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/Models/PromptSyntax/PromptSyntaxBuilder.cs:202
// 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();
}
// We're supposed to check `punctuation.definition.array.end.prompt` here, textmate is not parsing it
// separately always with current tmLanguage grammar, so ALSO use `meta.structure.weight.prompt` for now
// We check this AFTER `punctuation.separator.weight.prompt` to avoid consuming the ':'
else if (
nextToken.Scopes.Contains("punctuation.definition.array.end.prompt")
|| nextToken.Scopes.Contains("meta.structure.weight.prompt")
)
{
// Verify contents
if (GetTextSubstring(nextToken) != ")")
throw new InvalidOperationException("Expected closing parenthesis.");
ConsumeToken(); // Consume the ')'View on GitHub (pinned to af93d6ef57)