{"record":{"id":"9ffc1e7379d3d6de","repo":"BoundaryML/baml","slug":"expected-collector-got","errorCode":null,"errorMessage":"Expected Collector, got {}","messagePattern":"Expected Collector, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/function_args_decode.rs","lineNumber":44,"sourceCode":"            .kwargs\n            .into_iter()\n            .map(from_host_kv_to_baml_kv)\n            .collect::<Result<_, _>>()?;\n        let client_registry = from\n            .client_registry\n            .map(ClientRegistry::decode)\n            .transpose()?\n            .filter(|r| !r.is_empty());\n        let env_vars = from.env.into_iter().map(|e| (e.key, e.value)).collect();\n        let collectors = {\n            let collectors = from\n                .collectors\n                .into_iter()\n                .map(RawPtrType::decode)\n                .map(|r| match r {\n                    Ok(RawPtrType::Collector(c)) => Ok(c),\n                    Err(e) => Err(e),\n                    Ok(other) => Err(anyhow::anyhow!(\"Expected Collector, got {}\", other.name())),\n                })\n                .collect::<Result<Vec<_>, _>>()?;\n            if collectors.is_empty() {\n                None\n            } else {\n                Some(collectors)\n            }\n        };\n        let type_builder = from\n            .type_builder\n            .map(RawPtrType::decode)\n            .transpose()?\n            .map(|r| match r {\n                RawPtrType::TypeBuilder(t) => Ok(t),\n                other => Err(anyhow::anyhow!(\n                    \"Expected TypeBuilder, got {}\",\n                    other.name()\n                )),","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/function_args_decode.rs#L26-L62","documentation":"Thrown while decoding BamlFunctionArguments: the host passes a list of raw pointer objects expected to all be Collectors, but RawPtrType::decode resolved one of them to a different pointer type (the message includes the actual type name). This is a defensive check that the FFI object registry returns the right variant.","triggerScenarios":"Passing a non-Collector object (e.g. a TypeBuilder or runtime/client pointer) inside the collectors list of a function call's arguments.","commonSituations":"Mixing up object references in host code (passing the wrong handle/variable into a b.collectors-style argument), stale or recycled pointer IDs from the object registry, or version skew where pointer type tags shifted.","solutions":["Verify that the object you pass in the collectors argument is actually a Collector instance created via the BAML client's collector API","Recreate the object if its handle may be stale, and avoid reusing pointer IDs across calls","Align host SDK and engine versions so RawPtrType tags match what the decoder expects"],"exampleFix":"// before (host pseudocode)\nargs.collectors = [type_builder]  // wrong object\n\n// after\nargs.collectors = [baml_collector]  // actual Collector instance","handlingStrategy":"type-guard","validationCode":"# host side\nfor c in collectors:\n    if not isinstance(c, Collector):\n        raise TypeError(f\"collectors must contain Collector instances, got {type(c).__name__}\")","typeGuard":"function isCollector(obj) { return obj && obj.__baml_type === 'Collector'; }\nconst safeCollectors = maybeCollectors.filter(isCollector);","tryCatchPattern":"try:\n    result = client.CallFunction(fn, args)\nexcept Exception as e:\n    if \"Expected Collector\" in str(e):\n        raise TypeError(\"Pass only Collector objects in the collectors argument\") from e\n    raise","preventionTips":["Pass only objects obtained from the client's Collector factory into collectors","Do not reuse variable names that can shadow Collector handles with other BAML objects","Reacquire handles after runtime restarts instead of caching them"],"tags":["ffi","decode","type-mismatch","rust"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}