{"record":{"id":"eb8f6b43de689b41","repo":"Tencent/WeKnora","slug":"model-returned-invalid-suggestion-json","errorCode":null,"errorMessage":"model returned invalid suggestion JSON","messagePattern":"model returned invalid suggestion JSON","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/message_suggestion.go","lineNumber":811,"sourceCode":"\t\tQuestionID:      questionID,\n\t\tEventType:       eventType,\n\t\tActorID:         actorID,\n\t})\n}\n\ntype generatedSuggestionEnvelope struct {\n\tQuestions []struct {\n\t\tText     string `json:\"text\"`\n\t\tCategory string `json:\"category\"`\n\t} `json:\"questions\"`\n}\n\nfunc parseGeneratedSuggestions(content string, allowedCategories []string, limit int) (types.SuggestionItems, error) {\n\tcontent = strings.TrimSpace(suggestionThinkBlock.ReplaceAllString(content, \"\"))\n\tstart := strings.Index(content, \"{\")\n\tend := strings.LastIndex(content, \"}\")\n\tif start < 0 || end < start {\n\t\treturn nil, errors.New(\"model returned invalid suggestion JSON\")\n\t}\n\tvar envelope generatedSuggestionEnvelope\n\tif err := json.Unmarshal([]byte(content[start:end+1]), &envelope); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode suggestion JSON: %w\", err)\n\t}\n\tallowed := make(map[string]struct{}, len(allowedCategories))\n\tfor _, category := range allowedCategories {\n\t\tallowed[category] = struct{}{}\n\t}\n\tseen := make(map[string]struct{})\n\titems := make(types.SuggestionItems, 0, limit)\n\tfor _, question := range envelope.Questions {\n\t\ttext := strings.TrimSpace(question.Text)\n\t\tif text == \"\" || len([]rune(text)) > 200 {\n\t\t\tcontinue\n\t\t}\n\t\tkey := normalizeSuggestionText(text)\n\t\tif _, exists := seen[key]; exists {","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/message_suggestion.go#L793-L829","documentation":"Raised in parseGeneratedSuggestions when the LLM's suggestion content, after stripping think-blocks, contains no parseable JSON object (no '{'…'}' span) or JSON that fails to decode/validate — the model ignored the expected {questions:[{text,category}]} envelope. LLM output-format failure, not user input error.","triggerScenarios":"Thrown at internal/application/service/message_suggestion.go:811 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry generation with a stricter prompt/template enforcing the questions JSON schema","Log the raw model output for inspection; fall back to no suggestions rather than crashing"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}