weaviate/weaviate · error

failed to parse NER response (status %d): %w

Error message

failed to parse NER response (status %d): %w

What it means

The ner-transformers client's GetTokens reads the inference container's response and unmarshals it into nerResponse; a malformed body raises this error wrapped with the HTTP status code. Like the other vectorizer clients, parse failure is checked before the status-code check, so a bad body is reported even on error statuses.

Source

Thrown at modules/ner-transformers/clients/ner.go:92

		bytes.NewReader(body))
	if err != nil {
		return nil, errors.Wrap(err, "create POST request")
	}

	res, err := n.httpClient.Do(req)
	if err != nil {
		return nil, errors.Wrap(err, "send POST request")
	}
	defer res.Body.Close()

	bodyBytes, err := io.ReadAll(res.Body)
	if err != nil {
		return nil, errors.Wrap(err, "read response body")
	}

	var resBody nerResponse
	if err := json.Unmarshal(bodyBytes, &resBody); err != nil {
		return nil, fmt.Errorf("failed to parse NER response (status %d): %w", res.StatusCode, err)
	}

	if res.StatusCode > 399 {
		return nil, errors.Errorf("fail with status %d: %s", res.StatusCode, resBody.Error)
	}

	out := make([]ent.TokenResult, len(resBody.Tokens))

	for i, elem := range resBody.Tokens {
		out[i].Certainty = elem.Certainty
		out[i].Distance = elem.Distance
		out[i].Entity = elem.Entity
		out[i].Word = elem.Word
		out[i].StartPosition = elem.StartPosition
		out[i].EndPosition = elem.EndPosition
		out[i].Property = property
	}

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. Verify the inference URL points at the ner-transformers inference container (curl it and confirm JSON output)
  2. Inspect the wrapped %w error for the exact JSON decode failure
  3. Check the inference container logs for crashes or startup failure
  4. Pin matching versions of the weaviate module and the NER inference container
Defensive patterns

Strategy: try-catch

Validate before calling

ct := resp.Header.Get("Content-Type")
if !strings.Contains(ct, "application/json") {
  return fmt.Errorf("NER endpoint returned non-JSON (%s) — check inference URL", ct)
}
if len(bodyBytes) == 0 {
  return errors.New("NER endpoint returned empty body")
}

Type guard

func isValidNERResponse(b []byte) bool {
  var probe struct {
    Tokens []struct {
      Entity   string  `json:"entity"`
      Word     string  `json:"word"`
      Property string  `json:"property"`
      Certainty float64 `json:"certainty"`
    } `json:"tokens"`
  }
  return json.Unmarshal(b, &probe) == nil
}

Try / catch

tokens, err := nerClient.GetTokens(ctx, text)
if err != nil {
  var syntaxErr *json.SyntaxError
  if errors.As(err, &syntaxErr) {
    // truncated/invalid body — inspect the NER inference container
  }
  return fmt.Errorf("NER unavailable: %w", err)
}

Prevention

When it happens

Trigger: The NER inference container returns a body that fails json.Unmarshal — an HTML/proxy error page, empty or truncated body, or a response schema mismatch (e.g. different field names for tokens).

Common situations: ner-transformers inference container misconfigured or crashed; wrong NER_INFERENCE_URL / TRANSFORMERS_INFERENCE_URL pointing at a proxy or wrong service; module and inference container version mismatch after upgrade.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/e0e3e4d5ecf8566c. Report an issue: GitHub.