{"record":{"id":"5d8f30313d1fb7f5","repo":"LykosAI/StabilityMatrix","slug":"expected-numeric-weight-value","errorCode":null,"errorMessage":"Expected numeric weight value.","messagePattern":"Expected numeric weight value\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Core/Models/PromptSyntax/PromptSyntaxBuilder.cs","lineNumber":202,"sourceCode":"            // Check if no more tokens to consume.\n            if (PeekToken() is not { } nextToken)\n            {\n                // Ensure we have length set\n                if (node.Span.Length == 0)\n                    throw new InvalidOperationException(\"Unexpected end of input.\");\n                break;\n            }\n\n            if (nextToken.Scopes.Contains(\"punctuation.separator.weight.prompt\"))\n            {\n                // Parse the weight.\n                ConsumeToken(); // Consume the ':'\n\n                // Check the weight value token.\n                var weightToken = PeekToken();\n                if (weightToken is null || !weightToken.Scopes.Contains(\"constant.numeric\"))\n                {\n                    throw new InvalidOperationException(\"Expected numeric weight value.\");\n                }\n\n                // Consume the weight token.\n                node.Weight = ParseNumber();\n            }\n            // We're supposed to check `punctuation.definition.array.end.prompt` here, textmate is not parsing it\n            // separately always with current tmLanguage grammar, so ALSO use `meta.structure.weight.prompt` for now\n            // We check this AFTER `punctuation.separator.weight.prompt` to avoid consuming the ':'\n            else if (\n                nextToken.Scopes.Contains(\"punctuation.definition.array.end.prompt\")\n                || nextToken.Scopes.Contains(\"meta.structure.weight.prompt\")\n            )\n            {\n                // Verify contents\n                if (GetTextSubstring(nextToken) != \")\")\n                    throw new InvalidOperationException(\"Expected closing parenthesis.\");\n\n                ConsumeToken(); // Consume the ')'","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Core/Models/PromptSyntax/PromptSyntaxBuilder.cs#L184-L220","documentation":"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.","triggerScenarios":"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 ':'.","commonSituations":"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.","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"],"exampleFix":"// before\nvar prompt = \"(highly detailed:)\";\n// after\nvar prompt = \"(highly detailed:1.3)\";","handlingStrategy":"validation","validationCode":"var ok = System.Text.RegularExpressions.Regex.IsMatch(prompt, \"\\([^()]*:[0-9]+(\\.[0-9]+)?\\)\"); // each '(text:w)' group has a numeric weight","typeGuard":"null","tryCatchPattern":"try { var node = builder.Parse(prompt); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"weight\")) { // prompt user to fix the weight after ':' }","preventionTips":["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"],"tags":["parser","prompt-syntax","weight","numeric-token"],"backgroundTag":"invalid-argument-format","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}