{"record":{"id":"feb4a20ed577bd98","repo":"BoundaryML/baml","slug":"class-not-found-for-instance","errorCode":null,"errorMessage":"Class not found for instance: {:?}","messagePattern":"Class not found for instance: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-vm/src/test.rs","lineNumber":101,"sourceCode":"            VmObject::String(s) => Ok(Object::String(s.clone())),\n\n            VmObject::Array(arr) => arr\n                .iter()\n                .map(|v| Value::from_vm_value(v, vm))\n                .collect::<anyhow::Result<Vec<_>>>()\n                .map(Object::Array),\n\n            VmObject::Map(map) => map\n                .iter()\n                .map(|(key, value)| {\n                    Value::from_vm_value(value, vm).map(|value| (key.clone(), value))\n                })\n                .collect::<anyhow::Result<BamlMap<String, Value>>>()\n                .map(Object::Map),\n\n            VmObject::Instance(instance) => {\n                let VmObject::Class(vm_class) = &vm.objects[instance.class] else {\n                    anyhow::bail!(\"Class not found for instance: {:?}\", instance);\n                };\n\n                let mut fields = BamlMap::new();\n\n                for (i, value) in instance.fields.iter().enumerate() {\n                    let value = Value::from_vm_value(value, vm)?;\n                    fields.insert(vm_class.field_names[i].clone(), value);\n                }\n\n                Ok(Object::Instance(Instance {\n                    class: vm_class.name.clone(),\n                    fields,\n                }))\n            }\n\n            VmObject::Variant(variant) => {\n                let VmObject::Enum(vm_enum) = &vm.objects[variant.enm] else {\n                    anyhow::bail!(\"Enum not found for variant: {:?}\", variant);","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-vm/src/test.rs#L83-L119","documentation":"Converting a VmObject::Instance into a Value, the BAML VM looks up the instance's class in the object pool; if the slot at instance.class is not a Class, from_vm_object bails with \"Class not found for instance\". This is an internal VM invariant violation — instances should always point at a valid class.","triggerScenarios":"Calling BamlValue::from_vm_object (or Value::from_vm_value paths) on an Instance whose class index is dangling/corrupted in vm.objects — typically from a compiler/runtime mismatch or a VM bug during test execution.","commonSituations":"Version mismatch between generated BAML client code and the baml-vm/runtime; corrupted or stale compiled artifacts; running tests against sources recompiled mid-execution.","solutions":["Regenerate the BAML client (baml-cli generate) so generated code matches the runtime","Clean build artifacts and reinstall matching baml CLI/runtime versions","Reduce the failing test to the class definition involved and check for syntax/type issues","Report to BAML if reproducible on matching versions — it indicates a VM bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify version alignment before running tests\nconst rt = require('@boundaryml/baml/package.json').version;\nif (rt !== expectedCliVersion) throw new Error(`baml runtime ${rt} != CLI ${expectedCliVersion}; regenerate client`);","typeGuard":null,"tryCatchPattern":"match BamlValue::from_vm_object(instance, vm) {\n  Ok(v) => v,\n  Err(e) if e.to_string().contains(\"Class not found for instance\") => {\n    // regenerate client / flag VM corruption\n    anyhow::bail!(\"stale or corrupted BAML VM state: {e}\");\n  }\n  Err(e) => return Err(e),\n}","preventionTips":["Regenerate generated client code whenever .baml sources change","Pin baml CLI and runtime to the same version in CI","Avoid mutating/recompiling BAML sources while a VM session is running"],"tags":["vm","internal-error","rust","class"],"backgroundTag":"class-not-found","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"}