{"record":{"id":"4f46c701b81bdabb","repo":"BoundaryML/baml","slug":"key-is-missing","errorCode":null,"errorMessage":"Key is missing","messagePattern":"Key is missing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/baml_value_decode.rs","lineNumber":58,"sourceCode":"                .into_iter()\n                .map(|(k, v)| from_ffi_value_to_baml_value(v).map(|v| (k, v)))\n                .collect::<Result<_, _>>()?,\n        )),\n        crate::ffi::Value::Enum(e, value, _) => Ok(BamlValue::Enum(e, value)),\n    }\n}\n\npub(super) fn from_host_kv_to_baml_kv(\n    item: crate::baml::cffi::HostMapEntry,\n) -> Result<(String, BamlValue), anyhow::Error> {\n    use crate::baml::cffi::host_map_entry::Key;\n    let key = match item.key {\n        Some(Key::StringKey(key)) => key,\n        Some(Key::EnumKey(key)) => key.value,\n        Some(Key::IntKey(_)) | Some(Key::BoolKey(_)) => {\n            anyhow::bail!(\"only string keys are supported\")\n        }\n        None => anyhow::bail!(\"Key is missing\"),\n    };\n\n    let value = item\n        .value\n        .ok_or(anyhow::anyhow!(\"Value is null for key {}\", key))?;\n\n    Ok((key, BamlValue::decode(value)?))\n}\n","sourceCodeStart":40,"sourceCodeEnd":67,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/baml_value_decode.rs#L40-L67","documentation":"Thrown by from_host_kv_to_baml_kv when converting a host-language key/value pair into a BAML key/value pair and the protobuf HostMapEntry carries no key at all (the oneof `key` is None). The FFI boundary contract requires every map entry to have a key of a supported type, so a missing key is a malformed payload and the decode fails fast with anyhow::bail.","triggerScenarios":"A host caller (e.g. Python/Node via the CFFI) constructs or passes a map entry with key left unset when invoking BAML functions with kwargs/tags, or a protobuf HostMapEntry is built programmatically without setting the string_key/enum_key field.","commonSituations":"Version mismatch between the generated cffi bindings and the runtime (older host SDK omitting the key field), hand-constructed protobuf messages in tests, or serialization dropping null/empty keys before crossing the FFI boundary.","solutions":["Regenerate/upgrade the host-language BAML client bindings so they match the engine's cffi schema and always populate the key field","Inspect the payload being passed across the boundary and ensure every map entry sets string_key (or enum_key) before calling the BAML function","Check whether an intermediate serializer is dropping keys (e.g. null keys in a dict) and filter or reject such entries host-side before the call"],"exampleFix":"// before (host side, Python)\nkwargs = {None: \"v\"}\nclient.CallFunction(fn_name, kwargs)\n\n// after\nkwargs = {\"my_param\": \"v\"}\nclient.CallFunction(fn_name, kwargs)","handlingStrategy":"validation","validationCode":"# host side, before calling BAML\nbad = [k for k in entries if k is None or not isinstance(k, str)]\nif bad:\n    raise ValueError(f\"Map entries with missing/non-string keys: {bad}\")","typeGuard":"def has_valid_keys(entries: dict) -> bool:\n    return all(isinstance(k, str) for k in entries)","tryCatchPattern":"try:\n    result = client.CallFunction(fn, kwargs)\nexcept Exception as e:\n    if \"Key is missing\" in str(e):\n        raise ValueError(\"FFI map entry missing key; check bindings version and kwargs construction\") from e\n    raise","preventionTips":["Keep host BAML bindings and engine versions in lockstep","Never construct HostMapEntry objects by hand without setting the key field","Validate kwargs/tags key types host-side before every FFI call"],"tags":["ffi","decode","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"}