JuliusBrussee/caveman · error

helicone decode

Error message

helicone decode: %w

What it means

decodeHelicone first tries the {"data":[...]} envelope, then a bare array of heliconeRecord objects. This error wraps the underlying json.Unmarshal error when neither shape decodes, meaning the payload is not valid JSON in either accepted Helicone layout. The wrapped error names the exact JSON syntax/type problem.

Solutions

  1. Validate the payload parses as JSON and is either a bare array or an object with a `data` array
  2. Read the wrapped %w error to find the exact JSON offset/type failure and fix that field
  3. Ensure you are using the Helicone export format, not Langfuse/OTLP JSON
  4. Check heliconeRecord field types (all strings) against your data; pre-convert numeric fields to strings

Example fix

// before (wrong envelope for helicone)
{"observations":[{"id":"1"}]}
// after
{"data":[{"request_id":"1","created_at":"2024-01-01T00:00:00Z"}]}
Defensive patterns

Strategy: validation

Validate before calling

func isHeliconePayload(data []byte) bool {
  var env struct{ Data []json.RawMessage `json:"data"` }
  if err := json.Unmarshal(data, &env); err == nil && env.Data != nil { return true }
  var arr []json.RawMessage
  return json.Unmarshal(data, &arr) == nil
}

Try / catch

rows, err := importers.Parse(data, opts)
if err != nil {
  if strings.Contains(err.Error(), "helicone decode:") {
    return fmt.Errorf("payload is not a helicone array or {\"data\":[...]}: %w", err)
  }
  return err
}

Prevention

When it happens

Trigger: Calling Parse with FormatHelicone on data that is not a JSON array nor a {"data":[...]} object: malformed JSON, a JSON object without a `data` key, or a `data`/array whose elements do not match heliconeRecord field types (e.g. numeric request_body where a string is expected).

Common situations: Feeding Langfuse observations JSON to the Helicone importer; a truncated download; an API error body ({"error":...}) passed through; double-encoded JSON (a JSON string containing JSON); elements with wrong field types after an exporter version change.

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 JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/d706ff080fd956c3. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/importers/helicone.go:67

	recs, err := decodeHelicone(data)
	if err != nil {
		return nil, err
	}
	rows := make([]Span, 0, len(recs))
	for _, rec := range recs {
		rows = append(rows, mapHelicone(rec, opts))
	}
	return rows, nil
}

func decodeHelicone(data []byte) ([]heliconeRecord, error) {
	var env heliconeEnvelope
	if err := json.Unmarshal(data, &env); err == nil && env.Data != nil {
		return env.Data, nil
	}
	var arr []heliconeRecord
	if err := json.Unmarshal(data, &arr); err != nil {
		return nil, fmt.Errorf("helicone decode: %w", err)
	}
	return arr, nil
}

func mapHelicone(rec heliconeRecord, opts Options) Span {
	ts, _ := parseTimeFlexible(rec.CreatedAt)

	model := rec.Response.Model
	if model == "" {
		model = rec.Request.Model
	}
	provider := rec.Provider
	if provider == "" {
		provider = rec.Request.Provider
	}

	// 2xx is ok; anything else (including 0/unknown) is an error.
	status := "ok"

View on GitHub (pinned to 3ee70a1026)