Tencent/WeKnora · error
model returned invalid suggestion JSON
Error message
model returned invalid suggestion JSON
What it means
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.
Source
Thrown at internal/application/service/message_suggestion.go:811
QuestionID: questionID,
EventType: eventType,
ActorID: actorID,
})
}
type generatedSuggestionEnvelope struct {
Questions []struct {
Text string `json:"text"`
Category string `json:"category"`
} `json:"questions"`
}
func parseGeneratedSuggestions(content string, allowedCategories []string, limit int) (types.SuggestionItems, error) {
content = strings.TrimSpace(suggestionThinkBlock.ReplaceAllString(content, ""))
start := strings.Index(content, "{")
end := strings.LastIndex(content, "}")
if start < 0 || end < start {
return nil, errors.New("model returned invalid suggestion JSON")
}
var envelope generatedSuggestionEnvelope
if err := json.Unmarshal([]byte(content[start:end+1]), &envelope); err != nil {
return nil, fmt.Errorf("decode suggestion JSON: %w", err)
}
allowed := make(map[string]struct{}, len(allowedCategories))
for _, category := range allowedCategories {
allowed[category] = struct{}{}
}
seen := make(map[string]struct{})
items := make(types.SuggestionItems, 0, limit)
for _, question := range envelope.Questions {
text := strings.TrimSpace(question.Text)
if text == "" || len([]rune(text)) > 200 {
continue
}
key := normalizeSuggestionText(text)
if _, exists := seen[key]; exists {View on GitHub (pinned to 988cbb0330)
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
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at internal/application/service/message_suggestion.go:811 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/eb8f6b43de689b41.
Report an issue: GitHub.