{"record":{"id":"a5ffbfee63d68fc9","repo":"BoundaryML/baml","slug":"cannot-convert-object-of-type-type-name","errorCode":null,"errorMessage":"Cannot convert object of type {type_name}","messagePattern":"Cannot convert object of type (.+?)","errorType":"exception","errorClass":"EngineError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_engine/src/lib.rs","lineNumber":842,"sourceCode":"        source: bex_vm::errors::VmInternalError,\n        trace: Vec<bex_vm::StackFrame>,\n    },\n\n    /// Either a BAML panic or a BAML error value.\n    #[error(\"{}\", format_unhandled_throw(value, trace))]\n    UnhandledThrow {\n        value: Box<BexExternalValue>,\n        trace: Vec<bex_vm::StackFrame>,\n    },\n\n    /// Clean process-termination request from `baml.sys.exit(code)`.\n    /// The caller is expected to honor this as the process exit code.\n    /// BAML `int` is `i64`, so the signal carries the full value; the\n    /// caller clamps into its shell's range (typically 0..=255 on Unix).\n    #[error(\"baml.sys.exit({code})\")]\n    Exit { code: i64 },\n\n    #[error(\"Cannot convert object of type {type_name}\")]\n    CannotConvert { type_name: String },\n\n    #[error(\"Type mismatch: {message}\")]\n    TypeMismatch { message: String },\n\n    #[error(\"Schema inconsistency: {message}\")]\n    SchemaInconsistency { message: String },\n\n    #[cfg(feature = \"heap_debug\")]\n    #[error(\"Snapshot not possible for type: {type_name}\")]\n    CannotSnapshot { type_name: String },\n\n    #[error(\"A function call with ID {call_id} is already in progress\")]\n    DuplicateCallId { call_id: CallId },\n\n    #[error(\"Package initialization failed: {0}\")]\n    InitFailed(String),\n","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_engine/src/lib.rs#L824-L860","documentation":"The engine was asked to convert a BAML object into a host/external representation but the object's type has no conversion defined. The message names the offending BAML type (type_name). It indicates a mismatch between what the host expects and what the VM produced.","triggerScenarios":"Calling APIs that export BAML values to the host (e.g. serialization/conversion entry points) with an object type lacking a converter — e.g. passing a class instance or opaque object where only primitives/maps are supported.","commonSituations":"Returning custom class instances from BAML functions to a host that expects JSON-able values; version changes adding new value kinds before converters exist.","solutions":["Return a convertible type (primitive, list, map) from the BAML function instead of the custom object","Convert the object to a plain representation inside BAML before returning","Check type_name and add/extend conversion support in the host integration","Upgrade the engine — newer versions may support converting this type"],"exampleFix":"// before (BAML)\nfunction f() { return MyClass(...) } // object not convertible\n// after\nfunction f() { return MyClass(...).to_dict() } // or return fields individually","handlingStrategy":"type-guard","validationCode":"fn convertible(v: &BexExternalValue) -> bool {\n    matches!(v, BexExternalValue::Null(_) | BexExternalValue::Int(_) | BexExternalValue::String(_) | BexExternalValue::List(_) | BexExternalValue::Map(_))\n}","typeGuard":"fn is_plain_value(v: &BexExternalValue) -> bool {\n    !matches!(v, BexExternalValue::Object(o) if o.is_class_instance())\n}","tryCatchPattern":null,"preventionTips":["Return only primitives/lists/maps from BAML entry points","Serialize objects to plain data inside BAML before crossing the boundary","Check supported conversion types for your engine version"],"tags":["conversion","type-mismatch","interop"],"backgroundTag":"incompatible-source-type","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}