{"record":{"id":"8b42174f72af52ee","repo":"BoundaryML/baml","slug":"only-string-keys-are-supported","errorCode":null,"errorMessage":"only string keys are supported","messagePattern":"only string keys are supported","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ctypes/baml_value_decode.rs","lineNumber":56,"sourceCode":"            c,\n            fields\n                .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":38,"sourceCodeEnd":67,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ctypes/baml_value_decode.rs#L38-L67","documentation":"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).","triggerScenarios":"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.","commonSituations":"Python dicts with int keys passed to BAML functions; serializing maps keyed by enums/ids without converting to strings first.","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"],"exampleFix":"// before\nmy_func({1: \"a\", 2: \"b\"})\n// after\nmy_func({\"1\": \"a\", \"2\": \"b\"})","handlingStrategy":"validation","validationCode":"function stringifyKeys(obj) {\n  return Object.fromEntries(Object.entries(obj).map(([k, v]) => [String(k), v]));\n}\nmyFunc(stringifyKeys({1: 'a', 2: 'b'}));","typeGuard":null,"tryCatchPattern":"try {\n  await bamlClient.MyFunction(mapArg);\n} catch (e) {\n  if (String(e).includes('only string keys are supported')) {\n    console.error('Convert all map keys to strings before calling BAML functions');\n  }\n}","preventionTips":["Always key maps with strings when calling BAML functions","Use BAML enums for enumerated keys","Normalize keys with a String() conversion at the boundary"],"tags":["cffi","ffi","map-keys","type-mismatch"],"backgroundTag":"type-mismatch","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"}