BoundaryML/baml · error

cannot convert value

Error message

cannot convert value {value} to VM value: enum '{enm}' not found

What it means

When converting a BamlValue::Enum back into a VM value, the runtime looks up the enum name among the function's resolved enums. This error means the enum name on the value has no matching enum definition in the resolved set.

Solutions

  1. Regenerate the BAML client so enum names match the current .baml schema
  2. Verify the enum name in the value exactly matches a declared enum (case-sensitive)
  3. Ensure the enum is part of the same project/function's resolved definitions
Defensive patterns

Strategy: validation

Validate before calling

assert enums_in_baml_project().contains("MyEnum")

Type guard

fn enum_name_known(name: &str, resolved: &HashMap<String, usize>) -> bool { resolved.contains_key(name) }

Try / catch

Err(e) if e.to_string().contains("enum '") => { /* fix enum name / regenerate */ }

Prevention

When it happens

Trigger: A function result or argument value carries an enum name not declared (or renamed/deleted) in the .baml files resolved for that function.

Common situations: Renaming an enum in .baml without regenerating clients; cross-project value sharing; typos in enum names when constructing values programmatically.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at engine/baml-runtime/src/async_vm_runtime.rs:1315

                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))
        }

        BamlValue::Enum(enm, variant) => {
            let Some(enum_index) = resolved_enums_names.get(enm) else {
                anyhow::bail!("cannot convert value {value} to VM value: enum '{enm}' not found");
            };

            let baml_vm::Object::Enum(enm) = &vm.objects[*enum_index] else {
                anyhow::bail!(
                    "internal error: cannot convert value {value} to VM value: enum '{enm}' not found in VM objects"
                );
            };

            let Some(variant_index) = enm.variant_names.iter().position(|v| v == variant) else {
                anyhow::bail!(
                    "cannot convert value {value} to VM value: enum '{enm}' has no variant '{variant}'"
                );
            };

            Ok(vm.alloc_variant(*enum_index, variant_index))
        }

        BamlValue::Media(media) => Ok(vm.alloc_media(media.clone())),

View on GitHub (pinned to bd85ce9dee)