BoundaryML/baml · critical

decodeCheckedValue: valueChecked is nil

Error message

decodeCheckedValue: valueChecked is nil

What it means

decodeCheckedValue panics when the *cffi.CFFIValueChecked is nil. A checked value (a value with assertion/check results) must carry a non-nil pointer so the decoder can read its value and checks; nil indicates malformed FFI data from the runtime.

Source

Thrown at engine/language_client_go/baml_go/serde/decode.go:292

			debugLog(" -> got a nil goType, so returning nil\n")
			// got a nill value, so return nil
			goType := convertFieldTypeToGoType(valueUnion.SelfType, typeMap)
			// goType should be a pointer
			ptr := reflect.New(goType)
			// use .Elem to return the inner pointer
			return ptr.Elem(), goType
		}
		ptr := reflect.New(goType)
		ptr.Elem().Set(value)
		return ptr, ptr.Type()
	}

	return value, goType
}

func decodeCheckedValue(valueChecked *cffi.CFFIValueChecked, typeMap TypeMap) (reflect.Value, reflect.Type) {
	if valueChecked == nil {
		panic("decodeCheckedValue: valueChecked is nil")
	}

	value := valueChecked.Value
	decodedValue, _ := Decode(value, typeMap)
	checks := make(map[string]shared.Check, len(valueChecked.Checks))
	for _, check := range valueChecked.Checks {
		checks[string(check.Name)] = shared.Check{
			Name:       string(check.Name),
			Expression: string(check.Expression),
			Status:     string(check.Status),
		}
	}
	goType, ok := typeMap.GetType(valueChecked.Name)
	if !ok {
		panic("error decoding value, checked type not found: " + valueChecked.Name.String())
	}
	checkedValue := reflect.New(goType)
	checkedValue.Elem().FieldByName("Value").Set(decodedValue)

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Regenerate baml_client and ensure the baml runtime version matches the Go bindings
  2. Guard call sites: skip/short-circuit decoding when the checked value is nil
  3. Wrap Decode in a recover() if processing untrusted/malformed responses
  4. Report the triggering payload to BAML maintainers

Example fix

// before
v, t := serde.Decode(cv, typeMap)
// after
if cv == nil || cv.ValueChecked == nil {
  return reflect.Value{}, nil
}
v, t := serde.Decode(cv, typeMap)
Defensive patterns

Strategy: type-guard

Validate before calling

if checked == nil { return reflect.Value{}, nil }

Type guard

func hasChecked(v *cffi.CFFIValue) bool { return v != nil && v.GetValueChecked() != nil }

Try / catch

defer func() { if r := recover(); r != nil { log.Printf("checked-value decode panic: %v", r) } }()
v, _ := serde.Decode(cv, typeMap)

Prevention

When it happens

Trigger: Decode() encountering a CFFIValue whose variant is a checked value with a nil CFFIValueChecked pointer.

Common situations: Version skew between generated client and native runtime, native-side bug producing empty checked values, or corrupted streaming responses.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/78c03c16e17f7bad. Report an issue: GitHub.