{"record":{"id":"830752250381397a","repo":"BoundaryML/baml","slug":"cannot-convert-value-value-to-vm-value-enum-enm-has-no","errorCode":null,"errorMessage":"cannot convert value {value} to VM value: enum '{enm}' has no variant '{variant}'","messagePattern":"cannot convert value (.+?) to VM value: enum '(.+?)' has no variant '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/async_vm_runtime.rs","lineNumber":1325,"sourceCode":"                )?);\n            }\n\n            Ok(vm.alloc_instance(*class_index, vm_fields_layout))\n        }\n\n        BamlValue::Enum(enm, variant) => {\n            let Some(enum_index) = resolved_enums_names.get(enm) else {\n                anyhow::bail!(\"cannot convert value {value} to VM value: enum '{enm}' not found\");\n            };\n\n            let baml_vm::Object::Enum(enm) = &vm.objects[*enum_index] else {\n                anyhow::bail!(\n                    \"internal error: cannot convert value {value} to VM value: enum '{enm}' not found in VM objects\"\n                );\n            };\n\n            let Some(variant_index) = enm.variant_names.iter().position(|v| v == variant) else {\n                anyhow::bail!(\n                    \"cannot convert value {value} to VM value: enum '{enm}' has no variant '{variant}'\"\n                );\n            };\n\n            Ok(vm.alloc_variant(*enum_index, variant_index))\n        }\n\n        BamlValue::Media(media) => Ok(vm.alloc_media(media.clone())),\n    }\n}\n\nfn try_vm_value_from_function_result(\n    vm: &mut Vm,\n    resolved_class_names: &HashMap<String, ObjectIndex>,\n    resolved_enums_names: &HashMap<String, ObjectIndex>,\n    result: anyhow::Result<FunctionResult>,\n) -> anyhow::Result<baml_vm::Value> {\n    let fn_result = result.context(\"failed to get function result\")?;","sourceCodeStart":1307,"sourceCodeEnd":1343,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/async_vm_runtime.rs#L1307-L1343","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (Rust)\nBamlValue::Enum(\"Status\".into(), \"Completed\".into())\n// after (Rust)\nBamlValue::Enum(\"Status\".into(), \"Complete\".into()) // matches enum Status { Complete | Failed }","handlingStrategy":"validation","validationCode":"assert enum_variants(\"Status\").contains(&variant)","typeGuard":"fn is_valid_variant(enm: &BamlEnumDef, v: &str) -> bool { enm.variant_names.iter().any(|n| n == v) }","tryCatchPattern":"Err(e) if e.to_string().contains(\"has no variant\") => { /* use a declared variant or update schema */ }","preventionTips":["Regenerate clients after variant changes","Validate LLM output variants against the enum before constructing values","Use exhaustive matching when mapping external strings to variants"],"tags":["baml","enum","variant"],"backgroundTag":"invalid-enum-value","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}