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
- Regenerate baml_client and ensure the baml runtime version matches the Go bindings
- Guard call sites: skip/short-circuit decoding when the checked value is nil
- Wrap Decode in a recover() if processing untrusted/malformed responses
- 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
- Verify non-nil CFFIValueChecked before decoding checks/asserts
- Keep generated client and runtime versions aligned
- Wrap streaming decodes in recover() since payloads can be partial
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
- decodeUnionValue: valueUnion is nil
- error decoding value
- panic(initErr)
- internal error: attempted to register unknown function '%s'
- failed to decode object response: %w
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/78c03c16e17f7bad.
Report an issue: GitHub.