BoundaryML/baml · error
Value is null for key {}
Error message
Value is null for key {} What it means
Thrown by from_host_map_entry once the key is validated as a string, when the entry's `value` field is None. The (String, Value) tuple cannot be built without a value, so the decode fails and includes the key name in the message.
Source
Thrown at engine/language_client_cffi/src/ctypes/cffi_value_decode.rs:58
HostVal::EnumValue(e) => Value::Enum(e.name, e.value, ()),
HostVal::Handle(handle) => {
let raw_ptr = RawPtrType::decode(handle)?;
Value::RawPtr(raw_ptr, ())
}
})
}
}
pub(super) fn from_host_map_entry(
item: crate::baml::cffi::HostMapEntry,
) -> Result<(String, Value), anyhow::Error> {
let key = match item.key {
Some(crate::baml::cffi::host_map_entry::Key::StringKey(k)) => k,
_ => return Err(anyhow::anyhow!("Key must be a string")),
};
let value = item
.value
.ok_or(anyhow::anyhow!("Value is null for key {}", key))?;
Ok((key, Value::decode(value)?))
}
View on GitHub (pinned to bd85ce9dee)
Solutions
- Always set the value field on host map entries; encode nulls explicitly as a null Value instead of omitting the field
- Upgrade host bindings/runtime so null values serialize correctly across the boundary
- Filter or error on entries with missing values host-side before invoking the BAML client
Example fix
// before (Python)
params = {"temperature": None}
// after
params = {"temperature": baml_null} # explicit encoded null value Defensive patterns
Strategy: validation
Validate before calling
if any(v is _unset_sentinel for v in entry_map.values()):
raise ValueError("Every map entry must carry an encoded value; use an explicit null") Type guard
def all_entries_have_values(entries) -> bool:
return all(getattr(e, 'value', None) is not None for e in entries) Try / catch
try:
result = client.CallFunction(fn, kwargs)
except Exception as e:
if "Value is null for key" in str(e):
raise ValueError("Map entry value missing; encode nulls explicitly or drop the entry") from e
raise Prevention
- Never leave the protobuf value field unset; use the bindings' null encoding
- Filter out None-valued entries host-side before the call
- Keep generated bindings and engine versions synchronized
When it happens
Trigger: A host map entry is constructed with StringKey set but value left unset — e.g. a kwarg present in the dict with no encoded value, or a serializer skipping None-valued fields in the protobuf message.
Common situations: Passing None values in dictionaries across the CFFI, version-skewed bindings that omit value serialization for empty/null values, or partially built HostMapEntry objects in tests.
Related errors
- Key is missing
- Value is null for key {}
- Failed to decode BamlValue
- Protobuf decode error: {0}
- Key must be a string
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/7a93152f671b62e3.
Report an issue: GitHub.