BoundaryML/baml · error

Class not found: {}

Error message

Class not found: {}

What it means

ClassBuilder::cls resolves the underlying class node by first checking the runtime IR, then the TypeBuilder itself. If the class name is found in neither, it bails with 'Class not found'. All ClassBuilder operations (type, list_properties, set_alias, etc.) go through this resolver, so this error surfaces from any of them.

Source

Thrown at engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs:215

                }
            }
        };

        builder.mode(target_mode)
    }

    fn cls(
        &self,
        rt: &BamlRuntime,
    ) -> anyhow::Result<std::sync::Arc<std::sync::Mutex<type_builder::ClassBuilder>>> {
        // if the IR defines the class, then its always valid
        if rt.ir.find_class(self.class_name.as_str()).is_ok() {
            let cls = self.type_builder.upsert_class(self.class_name.as_str());
            return Ok(cls);
        }

        let Some(cls) = self.type_builder.maybe_get_class(self.class_name.as_str()) else {
            anyhow::bail!("Class not found: {}", self.class_name);
        };
        Ok(cls)
    }

    pub fn r#type(&self, rt: &BamlRuntime) -> anyhow::Result<TypeIR> {
        self.mode.at_least(NodeRW::ReadOnly)?;
        let _ = self.cls(rt)?;

        Ok(TypeIR::class(self.class_name.as_str()))
    }

    pub fn list_properties(&self, rt: &BamlRuntime) -> anyhow::Result<Vec<ClassPropertyBuilder>> {
        self.mode.at_least(NodeRW::ReadOnly)?;

        let lock = self.cls(rt)?;
        let builder = lock.lock().unwrap();

        let ir_properties = match rt.ir.find_class(self.class_name.as_str()) {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Recreate the ClassBuilder from the current TypeBuilder via tb.class(rt, name)
  2. Verify the class name matches the BAML source exactly
  3. Avoid caching builders across runtime/TypeBuilder rebuilds

Example fix

// before
let cb = ClassBuilder::new(old_tb, "Resume");
cb.set_alias(rt, "CV")?; // stale builder -> class not found
// after
let cb = tb.class(rt, "Resume")?;
cb.set_alias(rt, "CV")?;
Defensive patterns

Strategy: try-catch

Validate before calling

// re-resolve builder from live TypeBuilder before use
let cb = tb.class(rt, "Resume")?;

Try / catch

match cb.set_alias(rt, alias) {
    Ok(_) => ...,
    Err(e) if e.to_string().contains("Class not found") => {
        let cb = tb.class(rt, "Resume")?;
        cb.set_alias(rt, alias)?;
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Using a ClassBuilder whose class name was removed or never registered on the attached TypeBuilder/IR, e.g. calling cb.set_alias / cb.list_properties on a stale or misnamed builder.

Common situations: Holding a ClassBuilder across a rebuild of the runtime/TypeBuilder; constructing ClassBuilder manually with a wrong name; renaming the class in BAML source while cached builders still use the old name.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/8dcbf0fa62f4ca2d. Report an issue: GitHub.