{"record":{"id":"f2d991eb882de87d","repo":"BoundaryML/baml","slug":"class-with-name-name-does-not-exist","errorCode":null,"errorMessage":"Class with name {name} does not exist","messagePattern":"Class with name (.+?) does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs","lineNumber":101,"sourceCode":"\n    pub fn class(&self, rt: &BamlRuntime, name: &str) -> anyhow::Result<ClassBuilder> {\n        match rt.ir.find_class(name) {\n            Ok(cls) => {\n                let _ = self.type_builder.upsert_class(name);\n                let builder = ClassBuilder::new(self.type_builder.clone(), name.to_string());\n                if !cls.item.attributes.dynamic() {\n                    Ok(builder.mode(NodeRW::ReadOnly))\n                } else {\n                    Ok(builder.mode(NodeRW::ReadWrite))\n                }\n            }\n            Err(_) => match self.type_builder.maybe_get_class(name) {\n                Some(_) => Ok(ClassBuilder::new(\n                    self.type_builder.clone(),\n                    name.to_string(),\n                )),\n                None => {\n                    anyhow::bail!(\"Class with name {name} does not exist\");\n                }\n            },\n        }\n    }\n\n    pub fn r#enum(&self, rt: &BamlRuntime, name: &str) -> anyhow::Result<EnumBuilder> {\n        match rt.ir.find_enum(name) {\n            Ok(enm) => {\n                let _ = self.type_builder.upsert_enum(name);\n                let builder = EnumBuilder::new(self.type_builder.clone(), name.to_string());\n                if !enm.item.attributes.dynamic() {\n                    return Ok(builder.mode(NodeRW::ReadOnly));\n                }\n                Ok(builder.mode(NodeRW::ReadWrite))\n            }\n            Err(_) => match self.type_builder.maybe_get_enum(name) {\n                Some(_) => Ok(EnumBuilder::new(\n                    self.type_builder.clone(),","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs#L83-L119","documentation":"TypeBuilder::class looks up an existing class builder by name. If the class exists in the runtime IR but was not added to this TypeBuilder (maybe_get_class returns None), or does not exist at all, the lookup fails with this error.","triggerScenarios":"Calling tb.class(rt, \"Name\") for a class name that is neither in the runtime IR nor in this TypeBuilder (typo, or the class was never added via add_class).","commonSituations":"Typo in the class name; calling .class() before add_class(); trying to modify a class registered on a different TypeBuilder instance.","solutions":["Add the class first with tb.add_class(rt, name) before looking it up","Verify the exact class name against the BAML source (case-sensitive)","Ensure you are using the same TypeBuilder instance the class was registered on"],"exampleFix":"// before\nlet cb = tb.class(rt, \"Resum\")?; // typo -> does not exist\n// after\nlet cb = match tb.class(rt, \"Resume\") {\n    Ok(cb) => cb,\n    Err(_) => tb.add_class(rt, \"Resume\")?,\n};","handlingStrategy":"try-catch","validationCode":"# verify name against known classes\nassert \"Resume\" in known_class_names, f\"class 'Resume' not defined\"","typeGuard":null,"tryCatchPattern":"try:\n    cb = tb.class(name)\nexcept Exception as e:\n    if \"does not exist\" in str(e):\n        cb = tb.add_class(rt, name)\n    else:\n        raise","preventionTips":["Call add_class before any lookup of a dynamic class","Double-check class name spelling and casing","Use a single TypeBuilder instance for the whole request lifecycle"],"tags":["type-builder","class","not-found","schema"],"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-14T16:17:12.679Z"}