{"record":{"id":"b60d0dead9d074ba","repo":"BoundaryML/baml","slug":"failed-to-decode-value","errorCode":null,"errorMessage":"Failed to decode Value","messagePattern":"Failed to decode Value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/object_args_decode.rs","lineNumber":62,"sourceCode":"}\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 {\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 Value\")),\n                    }\n                })\n                .collect::<Result<_, _>>()?,\n        })\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":69,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/object_args_decode.rs#L44-L69","documentation":"Thrown while decoding BAML object constructor kwargs when an entry has a string key but its value field is None/absent in the protobuf message. The library requires every named argument to carry a decodable Value; an empty value cannot be mapped to a BAML value.","triggerScenarios":"Passing an object constructor argument whose HostMapEntry contains Some(key) but no value variant in the oneof, typically from a mismatched client binding or a serialization bug.","commonSituations":"Version mismatch between the generated host-language client and the native CFFI binary, or host code that inserts placeholder entries with unset values into the kwargs map.","solutions":["Ensure all argument values are provided at the call site and none are silently dropped to None","Reinstall/upgrade the BAML client package so client and native library versions match","Check that no custom serialization layer strips value fields from map entries"],"exampleFix":"// before\nargs = {\"name\": \"x\", \"optional\": None}  # entry sent with unset value\n// after\nargs = {\"name\": \"x\"}  # omit unset args entirely","handlingStrategy":"validation","validationCode":"def validate_kwargs(kwargs):\n    for k, v in kwargs.items():\n        if v is None:\n            raise ValueError(f\"kwarg '{k}' has no value; omit it instead\")","typeGuard":"def has_value(entry): return entry.value is not None","tryCatchPattern":"try:\n    obj = CffiClass(**kwargs)\nexcept Exception as e:\n    if 'Failed to decode Value' in str(e):\n        kwargs = {k: v for k, v in kwargs.items() if v is not None}\n        obj = CffiClass(**kwargs)\n    else:\n        raise","preventionTips":["Omit None-valued arguments instead of passing them","Keep client and native library versions matched","Never hand-craft protobuf map entries"],"tags":["ffi","decoding","rust","protobuf"],"backgroundTag":"protobuf-unmarshal-failed","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"}