{"record":{"id":"5be07f518306dc2a","repo":"BoundaryML/baml","slug":"type-not-found-for-property-in-class","errorCode":null,"errorMessage":"Type not found for property {} in class {}","messagePattern":"Type not found for property (.+?) in class (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs","lineNumber":486,"sourceCode":"        Ok(result)\n    }\n\n    pub fn type_(&self, rt: &BamlRuntime) -> Result<TypeIR, anyhow::Error> {\n        self.mode.at_least(NodeRW::ReadOnly)?;\n\n        let ast_type = || {\n            if let Ok(cls) = rt.ir.find_class(self.class_name.as_str()) {\n                cls.find_field(&self.property_name)\n                    .map(|field| field.r#type().clone())\n            } else {\n                None\n            }\n        };\n\n        let prop = self.prop(rt)?;\n        let builder = prop.lock().unwrap();\n        let result = builder.r#type().or_else(ast_type).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Type not found for property {} in class {}\",\n                self.property_name,\n                self.class_name\n            )\n        });\n        result\n    }\n\n    pub fn set_description(&self, rt: &BamlRuntime, description: &str) -> anyhow::Result<()> {\n        self.mode.at_least(NodeRW::LLMOnly)?;\n\n        let prop = self.prop(rt)?;\n        let builder = prop.lock().unwrap();\n        builder.with_meta(\"description\", BamlValue::String(description.to_string()));\n        Ok(())\n    }\n\n    pub fn set_alias(&self, rt: &BamlRuntime, alias: &str) -> anyhow::Result<()> {","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs#L468-L504","documentation":"Thrown by ClassPropertyBuilder::type_() when neither the type-builder property nor the AST/IR definition carries a type for the property. The method tries builder.r#type() first and falls back to the AST type; if both are None it reports that no type could be resolved for the property.","triggerScenarios":"Calling .type_(rt) on a property that was upserted (e.g. via add_property or prop()) but whose TypeIR was never set, on a property that exists in the builder graph without a type, or on an IR property whose type is somehow absent.","commonSituations":" dynamically upserting a property without calling set_type(); partially constructed type builders; reading the type of a freshly created property before assignment.","solutions":["Call set_type(...) on the property builder before reading type_().","Use ClassBuilder::add_property(name, field_type) which sets the type atomically instead of a bare upsert.","Check that the .baml class field actually declares a type.","Read the type only after the type-builder graph is fully constructed."],"exampleFix":"// before\nlet prop = tb.class(\"Foo\").property(\"bar\");\nlet t = prop.type_(rt)?; // type never set\n// after\nlet prop = tb.class(\"Foo\").add_property(\"bar\", FieldType::string())?;\nlet t = prop.type_(rt)?;","handlingStrategy":"try-catch","validationCode":"// Ensure the type is set before reading it:\nlet prop = tb.class(\"Foo\").property(\"bar\");\n// if you created it dynamically, call add_property(name, ty) rather than a bare upsert","typeGuard":null,"tryCatchPattern":"let ty = match prop.type_(rt) {\n    Ok(t) => t,\n    Err(e) if e.to_string().contains(\"Type not found\") => set_default_type_then_read()?,\n    Err(e) => return Err(e),\n};","preventionTips":["Always create dynamic properties via add_property(), which sets a type.","Never read type_() on a property you just upserted without set_type().","Verify .baml fields always declare explicit types."],"tags":["type-builder","baml","rust","missing-type"],"backgroundTag":"missing-required-config-field","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"}