{"record":{"id":"dbda9d7ee5f14d33","repo":"BoundaryML/baml","slug":"enum-not-found-objects","errorCode":null,"errorMessage":"Enum not found: {}","messagePattern":"Enum not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs","lineNumber":563,"sourceCode":"            mode: NodeRW::ReadOnly,\n        }\n    }\n\n    fn mode(self, mode: NodeRW) -> Self {\n        Self { mode, ..self }\n    }\n\n    fn enm(\n        &self,\n        rt: &BamlRuntime,\n    ) -> anyhow::Result<std::sync::Arc<std::sync::Mutex<type_builder::EnumBuilder>>> {\n        // if the IR defines the enum, then its always valid\n        if rt.ir.find_enum(self.enum_name.as_str()).is_ok() {\n            return Ok(self.type_builder.upsert_enum(self.enum_name.as_str()));\n        }\n\n        let Some(enm) = self.type_builder.maybe_get_enum(self.enum_name.as_str()) else {\n            anyhow::bail!(\"Enum not found: {}\", self.enum_name);\n        };\n        Ok(enm)\n    }\n\n    fn create_value(&self, name: &str, rt: &BamlRuntime) -> EnumValueBuilder {\n        let target_mode = match self.mode {\n            NodeRW::ReadOnly => NodeRW::ReadOnly,\n            NodeRW::LLMOnly => NodeRW::LLMOnly,\n            NodeRW::ReadWrite => {\n                if let Ok(enm) = rt.ir.find_enum(self.enum_name.as_str()) {\n                    if enm.find_value(name).is_some() {\n                        NodeRW::LLMOnly\n                    } else {\n                        NodeRW::ReadWrite\n                    }\n                } else {\n                    NodeRW::ReadWrite\n                }","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs#L545-L581","documentation":"Thrown by EnumBuilder::enm(), the resolver used by add_value, set_description, set_alias, alias, description and type_. If the enum is not in the runtime IR, the builder looks in the type-builder graph via maybe_get_enum; when it's absent from both, it bails with 'Enum not found'. You are operating on an enum that exists nowhere.","triggerScenarios":"Calling tb.enum_(\"Color\").add_value(...)/description(...)/alias(...) where enum Color is neither defined in any .baml file nor upserted via tb.enum_(...) with add_value in the current type builder.","commonSituations":" typos in the enum name; referencing an enum removed or renamed in the schema; building an enum dynamically but calling value-level methods before any registration; wrong TypeBuilder instance.","solutions":["Define the enum in the .baml schema, or upsert it first with tb.enum_(\"Color\") and add at least one value.","Correct the enum name spelling to match the schema.","Verify the enum wasn't renamed/removed in recent .baml changes.","Ensure you're using the same TypeBuilder/BamlRuntime the enum was registered on."],"exampleFix":"// before\ntb.enum(\"Collar\").add_value(rt, \"red\")?; // enum 'Collar' doesn't exist\n// after\ntb.enum(\"Color\").add_value(rt, \"red\")?;","handlingStrategy":"validation","validationCode":"if rt.ir.find_enum(\"Color\").is_err() {\n    // upsert the enum and add values before calling add_value/description/alias\n    tb.enum_(\"Color\");\n}","typeGuard":null,"tryCatchPattern":"match enum_builder.add_value(rt, \"red\") {\n    Err(e) if e.to_string().starts_with(\"Enum not found\") => define_enum_first()?,\n    other => other,\n}","preventionTips":["Define enums in .baml or upsert them in the type builder before value operations.","Keep enum names as constants shared between schema and patch code.","Run a startup check that every enum referenced by runtime patches exists in the IR."],"tags":["type-builder","baml","rust","enum-lookup"],"backgroundTag":"entity-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"}