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

  1. Always set the value field on host map entries; encode nulls explicitly as a null Value instead of omitting the field
  2. Upgrade host bindings/runtime so null values serialize correctly across the boundary
  3. 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

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


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/7a93152f671b62e3. Report an issue: GitHub.