alibaba/open-code-review · error

grouping LLM returned empty response

Error message

grouping LLM returned empty response

What it means

When the grouping LLM responds successfully but the response content is an empty string, callGroupingLLM records this error on the session task record (rec.SetError) so the persisted history shows the failed attempt, before returning the same error to the caller. It means the API call succeeded but the model produced no usable text to parse into file groups.

Source

Thrown at internal/agent/grouping.go:228

		Model:     modelName,
		Messages:  messages,
		MaxTokens: maxTokens,
	})
	duration := time.Since(startTime)

	if err != nil {
		if rec != nil {
			rec.SetError(err, duration)
		}
		return nil, nil, fmt.Errorf("grouping LLM call: %w", err)
	}

	usage = resp.Usage

	content := resp.Content()
	if content == "" {
		if rec != nil {
			rec.SetError(fmt.Errorf("grouping LLM returned empty response"), duration)
		}
		return nil, usage, fmt.Errorf("grouping LLM returned empty response")
	}

	groups, err = parseGroupingResponse(content, diffs)
	if rec != nil {
		if err != nil {
			rec.SetError(fmt.Errorf("grouping response parse failed: %w", err), duration)
		} else {
			rec.SetResponse(resp, duration)
		}
	}
	return groups, usage, err
}

func buildFileList(diffs []model.Diff) string {
	var sb strings.Builder
	for _, d := range diffs {

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Increase the template's max token limit for the grouping task so the model has room to answer.
  2. Re-run; empty responses are often transient (sampled stop token).
  3. Verify the model supports the grouping prompt format and is not a tool-only model.
  4. Check provider logs/dashboard for content-filter flags on the request.

Example fix

// before
grouping maxTokens: 16  // model emits only a stop token
// after
grouping maxTokens: 2048 // template completion limit sized for the grouping JSON
Defensive patterns

Strategy: retry

Validate before calling

// ensure the template's grouping token limit is large enough before running
if template.GroupingMaxTokens < 512 { return fmt.Errorf("grouping max tokens too small (%d)", template.GroupingMaxTokens) }

Type guard

func hasContent(resp *llm.ChatResponse) bool { return resp != nil && resp.Content() != "" }

Try / catch

if _, _, err := callGroupingLLM(...); err != nil && strings.Contains(err.Error(), "empty response") {
    // retry once; empty completions are often transient
}

Prevention

When it happens

Trigger: callGroupingLLM receiving resp.Content() == "" — e.g. the model returned only a stop token, a tool call with no text, or the provider stripped the content due to a content filter or max_tokens=0-equivalent truncation.

Common situations: maxTokens configured too low (TestCallGroupingLLM_UsesTemplateMaxTokens suggests template-driven limits) so output is truncated to nothing; provider content-filter suppression; wrong model that doesn't follow the grouping prompt at all.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/2cfb2df54859cd4c. Report an issue: GitHub.