BoundaryML/baml · error
cannot convert value
Error message
cannot convert value {value} to VM value: enum '{enm}' has no variant '{variant}' What it means
Runtime conversion error while marshaling a BamlValue into a VM object: the value is an Enum whose variant name does not exist in the resolved enum definition known to the VM. This happens when the enum's variants changed between compile time and call time (stale bytecode vs. fresh types), or the variant name was never declared — the conversion refuses to invent a variant.
Solutions
- Update the variant name to one declared in the .baml enum (exact match)
- Regenerate the client after enum changes
- Validate LLM-parsed output against the enum's variant list before constructing values
Example fix
// before (Rust)
BamlValue::Enum("Status".into(), "Completed".into())
// after (Rust)
BamlValue::Enum("Status".into(), "Complete".into()) // matches enum Status { Complete | Failed } Defensive patterns
Strategy: validation
Validate before calling
assert enum_variants("Status").contains(&variant) Type guard
fn is_valid_variant(enm: &BamlEnumDef, v: &str) -> bool { enm.variant_names.iter().any(|n| n == v) } Try / catch
Err(e) if e.to_string().contains("has no variant") => { /* use a declared variant or update schema */ } Prevention
- Regenerate clients after variant changes
- Validate LLM output variants against the enum before constructing values
- Use exhaustive matching when mapping external strings to variants
When it happens
Trigger: Constructing a BamlValue::Enum with a variant name that is misspelled or no longer exists in the .baml enum definition, then passing it to a function.
Common situations: Removing/renaming an enum variant in .baml without regenerating clients; LLM output producing an invalid variant that was constructed into a value instead of rejected; programmatic value building with typos.
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/830752250381397a.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-runtime/src/async_vm_runtime.rs:1325
)?);
}
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())),
}
}
fn try_vm_value_from_function_result(
vm: &mut Vm,
resolved_class_names: &HashMap<String, ObjectIndex>,
resolved_enums_names: &HashMap<String, ObjectIndex>,
result: anyhow::Result<FunctionResult>,
) -> anyhow::Result<baml_vm::Value> {
let fn_result = result.context("failed to get function result")?;View on GitHub (pinned to bd85ce9dee)