BoundaryML/baml · error
cannot convert value
Error message
cannot convert value {value} to VM value: class '{name}' has no field '{field_name}' What it means
When materializing a BamlValue::Class into a VM value, the runtime iterates the VM class's declared field names and requires each one to be present in the value's field map. This error means the value is missing a field that the class declares.
Solutions
- Populate every declared field of the class in the value's field map (use null for optional fields)
- Regenerate the client after changing the .baml class so field lists match
- Compare the field map keys against the class definition in the .baml file
Example fix
// before (Rust)
BamlValue::Class("User".into(), vec![("name".into(), BamlValue::String("a".into()))].into_iter().collect())
// after (Rust)
BamlValue::Class("User".into(), vec![("name".into(), BamlValue::String("a".into())), ("age".into(), BamlValue::Int(0))].into_iter().collect()) Defensive patterns
Strategy: validation
Validate before calling
// check all declared fields present before constructing value
for f in class.field_names { assert!(fields.contains_key(f), "missing field {f}") } Type guard
fn has_all_fields(fields: &HashMap<String, BamlValue>, required: &[&str]) -> bool { required.iter().all(|f| fields.contains_key(*f)) } Try / catch
Err(e) if e.to_string().contains("has no field") => { /* add missing field or regenerate client */ } Prevention
- Regenerate the client after adding fields to a class
- Initialize all fields when building class values programmatically
- Use nullable defaults for optional fields
When it happens
Trigger: Constructing a BamlValue::Class (e.g. from code that builds function arguments or results) with a field map that lacks one of the class's declared fields, then calling a function with it.
Common situations: Manually building class values in Rust/Python/TS integrations and forgetting a newly added field after editing the .baml class; optional/nullable handling changes; partial deserialization dropping fields.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/0d31b024bb9026f3.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-runtime/src/async_vm_runtime.rs:1292
Ok(vm.alloc_map(vm_map))
}
BamlValue::Class(name, fields) => {
let Some(class_index) = resolved_class_names.get(name) else {
anyhow::bail!("cannot convert value {value} to VM value: class '{name}' not found");
};
let baml_vm::Object::Class(class) = &vm.objects[*class_index] else {
anyhow::bail!(
"internal error: cannot convert value {value} to VM value: class '{name}' not found in VM objects"
);
};
let mut ordered_field_values = Vec::new();
for field_name in &class.field_names {
let Some(value) = fields.get(field_name) else {
anyhow::bail!(
"cannot convert value {value} to VM value: class '{name}' has no field '{field_name}'"
);
};
ordered_field_values.push(value);
}
let mut vm_fields_layout = Vec::new();
for v in ordered_field_values {
vm_fields_layout.push(try_vm_value_from_baml_value(
vm,
resolved_class_names,
resolved_enums_names,
v,
)?);
}
Ok(vm.alloc_instance(*class_index, vm_fields_layout))View on GitHub (pinned to bd85ce9dee)