{"record":{"id":"60384b1e0be85206","repo":"BoundaryML/baml","slug":"value-is-null-for-key","errorCode":null,"errorMessage":"Value is null for key {}","messagePattern":"Value is null for key (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/baml_value_decode.rs","lineNumber":63,"sourceCode":"    }\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":45,"sourceCodeEnd":67,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/baml_value_decode.rs#L45-L67","documentation":"Thrown by from_host_kv_to_baml_kv after the key has been resolved, when the HostMapEntry's `value` field is None. A key/value pair must carry both parts; a present key with a null value cannot be represented as a BamlValue, so the decode bails with the offending key name in the message.","triggerScenarios":"A host caller passes a map entry whose value was not set (protobuf oneof/value absent), e.g. function arguments, tags, or kwargs where one parameter was declared but given no value.","commonSituations":"Passing None/null parameter values through the CFFI without wrapping them as an explicit BAML null, binding/runtime version skew, or builders that add keys before assigning values.","solutions":["Ensure every argument/tag entry has its value set before crossing the FFI boundary; represent nulls as an explicit BamlValue::Null rather than an unset field","Upgrade the host SDK/bindings to match the engine version so optional-value serialization is consistent","Validate the kwargs/tags map host-side and drop or fill entries with missing values before calling the BAML function"],"exampleFix":"// before (host side)\nkwargs = {\"model\": None}  // value field left unset\n\n// after\nkwargs = {\"model\": client.baml_options.null_value}  // explicit null BamlValue","handlingStrategy":"validation","validationCode":"# host side\nmissing = [k for k, v in kwargs.items() if v is _unset_sentinel]\nif missing:\n    raise ValueError(f\"Arguments with no encoded value: {missing}\")","typeGuard":"def all_values_set(entries: dict) -> bool:\n    return all(v is not _unset_sentinel for v in entries.values())","tryCatchPattern":"try:\n    result = client.CallFunction(fn, kwargs)\nexcept Exception as e:\n    if \"Value is null for key\" in str(e):\n        raise ValueError(f\"Pass an explicit BAML null instead of an unset value for: {e}\") from e\n    raise","preventionTips":["Encode null parameters as explicit BAML null values, not omitted fields","Use the official client builder APIs rather than hand-building protobuf messages","Pin matching versions of the generated bindings and runtime"],"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-14T11:17:12.474Z"}