BoundaryML/baml · error

unsupported raw pointer type

Error message

unsupported raw pointer type

What it means

When decoding FFI values back into BamlValue, RawPtr values are only understood when they wrap Media data. Any other RawPtrType cannot be converted and the decoder bails with this error — a pointer of an unexpected kind crossed the FFI boundary.

Source

Thrown at engine/language_client_cffi/src/ctypes/baml_value_decode.rs:35

        crate::ffi::Value::String(s, _) => Ok(BamlValue::String(s)),
        crate::ffi::Value::Int(i, _) => Ok(BamlValue::Int(i)),
        crate::ffi::Value::Float(f, _) => Ok(BamlValue::Float(f)),
        crate::ffi::Value::Bool(b, _) => Ok(BamlValue::Bool(b)),
        crate::ffi::Value::Map(m, _) => Ok(BamlValue::Map(
            m.into_iter()
                .map(|(k, v)| from_ffi_value_to_baml_value(v).map(|v| (k, v)))
                .collect::<Result<_, _>>()?,
        )),
        crate::ffi::Value::List(l, _) => Ok(BamlValue::List(
            l.into_iter()
                .map(from_ffi_value_to_baml_value)
                .collect::<Result<_, _>>()?,
        )),
        crate::ffi::Value::RawPtr(r, _) => match r {
            crate::raw_ptr_wrapper::RawPtrType::Media(raw_ptr_wrapper) => {
                Ok(BamlValue::Media(raw_ptr_wrapper.as_ref().clone()))
            }
            _ => anyhow::bail!("unsupported raw pointer type"),
        },
        crate::ffi::Value::Class(c, fields, _) => Ok(BamlValue::Class(
            c,
            fields
                .into_iter()
                .map(|(k, v)| from_ffi_value_to_baml_value(v).map(|v| (k, v)))
                .collect::<Result<_, _>>()?,
        )),
        crate::ffi::Value::Enum(e, value, _) => Ok(BamlValue::Enum(e, value)),
    }
}

pub(super) fn from_host_kv_to_baml_kv(
    item: crate::baml::cffi::HostMapEntry,
) -> Result<(String, BamlValue), anyhow::Error> {
    use crate::baml::cffi::host_map_entry::Key;
    let key = match item.key {
        Some(Key::StringKey(key)) => key,

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure the host bindings and the BAML runtime are the same version (reinstall matching packages)
  2. Pass media (images/audio) as supported Media objects, not other pointer types
  3. Pass plain values (strings, ints, maps) instead of raw pointers where possible
  4. If reproducible with matching versions, file a bug with a minimal repro
Defensive patterns

Strategy: type-guard

Type guard

function isMediaArg(v) {
  return v instanceof Image || v instanceof Audio || typeof v === 'string' || typeof v === 'number';
}
// only pass media/raw-pointer-supported values across the FFI boundary

Try / catch

try {
  const out = await bamlClient.MyFunction(args);
} catch (e) {
  if (String(e).includes('unsupported raw pointer type')) {
    console.error('Unsupported object passed over FFI; pass media or plain values');
  }
}

Prevention

When it happens

Trigger: Calling a BAML function through the CFFI decode path where the host passed or the runtime returned a Value::RawPtr whose RawPtrType is not Media (e.g. another pointer variant), typically from an internal API misuse or version-mismatched host library.

Common situations: Mixing versions of the CFFI host binding and the BAML runtime; passing an unsupported opaque object (non-media) through FFI arguments; internal bug in pointer type tagging.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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