{"record":{"id":"874b7ae81196b186","repo":"BoundaryML/baml","slug":"failed-to-decode-bamlvalue","errorCode":null,"errorMessage":"Failed to decode BamlValue","messagePattern":"Failed to decode BamlValue","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/object_args_decode.rs","lineNumber":38,"sourceCode":"        Ok(BamlMethodArguments {\n            object: match from.object.map(RawPtrType::decode).transpose()? {\n                Some(object) => object,\n                None => {\n                    return Err(anyhow::anyhow!(\"Failed to decode RawPtrType for object\"));\n                }\n            },\n            method_name: from.method_name,\n            kwargs: from\n                .kwargs\n                .into_iter()\n                .map(|v| {\n                    let key = match v.key {\n                        Some(crate::baml::cffi::host_map_entry::Key::StringKey(k)) => k,\n                        _ => return Err(anyhow::anyhow!(\"Key must be a string\")),\n                    };\n                    match v.value {\n                        Some(value) => Ok((key, Value::decode(value)?)),\n                        None => Err(anyhow::anyhow!(\"Failed to decode BamlValue\")),\n                    }\n                })\n                .collect::<Result<_, _>>()?,\n        })\n    }\n}\n\nimpl Decode for BamlObjectConstructorArgs {\n    type From = crate::baml::cffi::BamlObjectConstructorInvocation;\n\n    fn decode(from: Self::From) -> Result<Self, anyhow::Error> {\n        Ok(BamlObjectConstructorArgs {\n            object_type: BamlObjectType::try_from(from.r#type)?,\n            kwargs: from\n                .kwargs\n                .into_iter()\n                .map(|v| {\n                    let key = match v.key {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/object_args_decode.rs#L20-L56","documentation":"Thrown inside BamlMethodArguments::decode when a kwargs entry has a valid string key but its `value` field is None, so Value::decode cannot be performed. The generic message does not name the key because the guard is a simple None match on the value.","triggerScenarios":"A method-call kwarg is present with no encoded value — e.g. passing None/null values that the serializer drops instead of encoding as an explicit null Value.","commonSituations":"Calling BAML object methods with None-valued parameters, bindings that serialize absent optional fields by omission, or hand-built HostMapEntry objects in tests missing the value.","solutions":["Encode nulls explicitly as a null Value (per the bindings' null representation) instead of leaving the protobuf field unset","Omit None-valued kwargs from the map entirely rather than passing entries without values","Upgrade host bindings/runtime together so optional value serialization is consistent"],"exampleFix":"// before (Python)\nkwargs = {\"options\": None}\nclient.CallMethod(\"m\", kwargs)\n\n// after\nkwargs = {k: v for k, v in kwargs.items() if v is not None}\nclient.CallMethod(\"m\", kwargs)","handlingStrategy":"validation","validationCode":"clean_kwargs = {k: v for k, v in kwargs.items() if v is not None}\n# or, if nulls are meaningful, use the bindings' explicit null value\nclean_kwargs = {k: (v if v is not None else baml_null) for k, v in kwargs.items()}","typeGuard":"def all_kwargs_encoded(kwargs: dict) -> bool:\n    return all(v is not _unset_sentinel for v in kwargs.values())","tryCatchPattern":"try:\n    result = obj.CallMethod(method, kwargs)\nexcept Exception as e:\n    if \"Failed to decode BamlValue\" in str(e):\n        raise ValueError(\"A kwarg had no encoded value; pass an explicit null or drop the entry\") from e\n    raise","preventionTips":["Never pass sentinel/unset values in kwargs; encode nulls explicitly","Strip or fill None-valued parameters before FFI calls","Regenerate bindings whenever the cffi schema changes"],"tags":["ffi","decode","kwargs","protobuf","rust"],"backgroundTag":"null-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}