JuliusBrussee/caveman · error
langfuse decode
Error message
langfuse decode: %w
What it means
decodeLangfuse tries the {"observations":[...]} envelope first, then a bare array of langfuseObservation objects. This error wraps the json.Unmarshal failure when the payload is neither shape, so no Langfuse observations can be decoded. The wrapped error pinpoints the JSON problem.
Solutions
- Confirm the payload is either a bare JSON array of observations or {"observations":[...]}
- Read the wrapped %w error for the exact JSON decode failure (offset/field) and fix it
- Verify you selected the langfuse format, not helicone/generic, for this payload
- Check element field types against langfuseObservation and pre-convert mismatches
Example fix
// before (helicone-style envelope)
{"data":[{"id":"1"}]}
// after
{"observations":[{"id":"1","start_time":"2024-01-01T00:00:00Z"}]} Defensive patterns
Strategy: validation
Validate before calling
func isLangfusePayload(data []byte) bool {
var env struct{ Observations []json.RawMessage `json:"observations"` }
if err := json.Unmarshal(data, &env); err == nil && env.Observations != 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(), "langfuse decode:") {
return fmt.Errorf("payload is not a langfuse array or {\"observations\":[...]}: %w", err)
}
return err
} Prevention
- Validate JSON syntax and envelope key before import
- Use the langfuse format only for Langfuse observation exports
- Check element field types against langfuseObservation before import
- Guard against API error bodies and truncated downloads reaching the importer
When it happens
Trigger: Calling Parse with FormatLangfuse on data that is not a JSON array nor an object with an `observations` array: malformed JSON, a different envelope key (e.g. `data`), or array elements whose field types do not match langfuseObservation (e.g. numeric id, object where a string timestamp is expected).
Common situations: Feeding Helicone export JSON to the Langfuse importer; Langfuse API error bodies passed through; truncated export downloads; Langfuse API version changing field types; double-encoded JSON strings.
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
- generic decode: expected a JSON array or
- helicone decode
- array not closed
- assembly slot content is not JSON-serializable
- assembly slot content is not JSON-serializable
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/c482b2e634e63fde.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/importers/langfuse.go:63
obs, err := decodeLangfuse(data)
if err != nil {
return nil, err
}
rows := make([]Span, 0, len(obs))
for _, o := range obs {
rows = append(rows, mapLangfuse(o, opts))
}
return rows, nil
}
func decodeLangfuse(data []byte) ([]langfuseObservation, error) {
var env langfuseEnvelope
if err := json.Unmarshal(data, &env); err == nil && env.Observations != nil {
return env.Observations, nil
}
var arr []langfuseObservation
if err := json.Unmarshal(data, &arr); err != nil {
return nil, fmt.Errorf("langfuse decode: %w", err)
}
return arr, nil
}
func mapLangfuse(o langfuseObservation, opts Options) Span {
start, startNs := parseTimeFlexible(o.StartTime)
end, endNs := parseTimeFlexible(o.EndTime)
status := "ok"
switch o.Level {
case "ERROR":
status = "error"
case "WARNING":
status = "unset"
}
spanType := o.Type
if spanType == "" {View on GitHub (pinned to 3ee70a1026)