BoundaryML/baml · error

Failed to decode RawPtrType for object

Error message

Failed to decode RawPtrType for object

What it means

Thrown by BamlMethodArguments::decode when the `object` field is present but RawPtrType::decode fails, or — as guarded here — when the object field is absent entirely. A method call over the FFI must name a registered object; without a decodable raw pointer there is nothing to invoke the method on.

Solutions

  1. Verify a valid object handle is being passed to the method call and that it was created by the same client instance
  2. Recreate the object (e.g. re-create the client or collector) if its handle may have been freed when the runtime shut down
  3. Align host SDK and engine versions so handle registration/decoding is compatible

Example fix

// before (host pseudocode)
stale_client.CallMethod("fn")  // object handle gone

// after
client = baml.Client()
client.CallMethod("fn")
Defensive patterns

Strategy: validation

Validate before calling

# host side, before invoking a method
if obj is None or obj.handle is None:
    raise ValueError("No object handle set; create the object via the client before calling methods")

Type guard

function hasLiveHandle(obj) { return obj != null && typeof obj.__handle === 'number' && obj.__handle >= 0; }

Try / catch

try:
    result = obj.CallMethod(method, kwargs)
except Exception as e:
    if "Failed to decode RawPtrType" in str(e):
        obj = recreate_object(client)  # handle was stale/unregistered
        result = obj.CallMethod(method, kwargs)
    else:
        raise

Prevention

When it happens

Trigger: Calling client.object_call / method invocation with no object handle set, or with a pointer ID the decoder cannot resolve (unregistered or freed handle).

Common situations: Invoking a method on an object after the client/runtime was shut down, passing a null handle from host code, or version-skewed bindings where handle registration changed.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at engine/language_client_cffi/src/ctypes/object_args_decode.rs:24

    pub object: RawPtrType,
    pub method_name: String,
    pub kwargs: baml_types::BamlMap<String, crate::ffi::Value>,
}

pub struct BamlObjectConstructorArgs {
    pub object_type: BamlObjectType,
    pub kwargs: baml_types::BamlMap<String, crate::ffi::Value>,
}

impl Decode for BamlMethodArguments {
    type From = crate::baml::cffi::BamlObjectMethodInvocation;

    fn decode(from: Self::From) -> Result<Self, anyhow::Error> {
        Ok(BamlMethodArguments {
            object: match from.object.map(RawPtrType::decode).transpose()? {
                Some(object) => object,
                None => {
                    return Err(anyhow::anyhow!("Failed to decode RawPtrType for object"));
                }
            },
            method_name: from.method_name,
            kwargs: from
                .kwargs
                .into_iter()
                .map(|v| {
                    let key = match v.key {
                        Some(crate::baml::cffi::host_map_entry::Key::StringKey(k)) => k,
                        _ => return Err(anyhow::anyhow!("Key must be a string")),
                    };
                    match v.value {
                        Some(value) => Ok((key, Value::decode(value)?)),
                        None => Err(anyhow::anyhow!("Failed to decode BamlValue")),
                    }
                })
                .collect::<Result<_, _>>()?,
        })

View on GitHub (pinned to bd85ce9dee)