BoundaryML/baml · error
only string keys are supported
Error message
only string keys are supported
What it means
Host map entries crossing the FFI boundary must have string-convertible keys. If the host sends a map entry keyed by int or bool, the decoder rejects it since BAML map keys in this surface are strings (enum keys are accepted via their string value).
Solutions
- Convert numeric/boolean keys to strings before passing the map to the BAML function
- Ensure all map keys are strings (or BAML enums)
- Adjust the BAML function signature to accept the keyed data as a class or list of pairs
Example fix
// before
my_func({1: "a", 2: "b"})
// after
my_func({"1": "a", "2": "b"}) Defensive patterns
Strategy: validation
Validate before calling
function stringifyKeys(obj) {
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [String(k), v]));
}
myFunc(stringifyKeys({1: 'a', 2: 'b'})); Try / catch
try {
await bamlClient.MyFunction(mapArg);
} catch (e) {
if (String(e).includes('only string keys are supported')) {
console.error('Convert all map keys to strings before calling BAML functions');
}
} Prevention
- Always key maps with strings when calling BAML functions
- Use BAML enums for enumerated keys
- Normalize keys with a String() conversion at the boundary
When it happens
Trigger: Calling a BAML function with a map/dictionary argument whose key is an int or bool (e.g. {1: 'x'} or {true: 'x'}) through the CFFI layer.
Common situations: Python dicts with int keys passed to BAML functions; serializing maps keyed by enums/ids without converting to strings first.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- unsupported raw pointer type
- baml.panics.HostContractViolation
- Expected Collector, got
- Expected string value for tag key
- Expected TypeBuilder, got
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/8b42174f72af52ee.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_client_cffi/src/ctypes/baml_value_decode.rs:56
c,
fields
.into_iter()
.map(|(k, v)| from_ffi_value_to_baml_value(v).map(|v| (k, v)))
.collect::<Result<_, _>>()?,
)),
crate::ffi::Value::Enum(e, value, _) => Ok(BamlValue::Enum(e, value)),
}
}
pub(super) fn from_host_kv_to_baml_kv(
item: crate::baml::cffi::HostMapEntry,
) -> Result<(String, BamlValue), anyhow::Error> {
use crate::baml::cffi::host_map_entry::Key;
let key = match item.key {
Some(Key::StringKey(key)) => key,
Some(Key::EnumKey(key)) => key.value,
Some(Key::IntKey(_)) | Some(Key::BoolKey(_)) => {
anyhow::bail!("only string keys are supported")
}
None => anyhow::bail!("Key is missing"),
};
let value = item
.value
.ok_or(anyhow::anyhow!("Value is null for key {}", key))?;
Ok((key, BamlValue::decode(value)?))
}
View on GitHub (pinned to bd85ce9dee)