BoundaryML/baml · error
Class with name {name} does not exist
Error message
Class with name {name} does not exist What it means
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.
Source
Thrown at engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs:101
pub fn class(&self, rt: &BamlRuntime, name: &str) -> anyhow::Result<ClassBuilder> {
match rt.ir.find_class(name) {
Ok(cls) => {
let _ = self.type_builder.upsert_class(name);
let builder = ClassBuilder::new(self.type_builder.clone(), name.to_string());
if !cls.item.attributes.dynamic() {
Ok(builder.mode(NodeRW::ReadOnly))
} else {
Ok(builder.mode(NodeRW::ReadWrite))
}
}
Err(_) => match self.type_builder.maybe_get_class(name) {
Some(_) => Ok(ClassBuilder::new(
self.type_builder.clone(),
name.to_string(),
)),
None => {
anyhow::bail!("Class with name {name} does not exist");
}
},
}
}
pub fn r#enum(&self, rt: &BamlRuntime, name: &str) -> anyhow::Result<EnumBuilder> {
match rt.ir.find_enum(name) {
Ok(enm) => {
let _ = self.type_builder.upsert_enum(name);
let builder = EnumBuilder::new(self.type_builder.clone(), name.to_string());
if !enm.item.attributes.dynamic() {
return Ok(builder.mode(NodeRW::ReadOnly));
}
Ok(builder.mode(NodeRW::ReadWrite))
}
Err(_) => match self.type_builder.maybe_get_enum(name) {
Some(_) => Ok(EnumBuilder::new(
self.type_builder.clone(),View on GitHub (pinned to bd85ce9dee)
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
Example fix
// before
let cb = tb.class(rt, "Resum")?; // typo -> does not exist
// after
let cb = match tb.class(rt, "Resume") {
Ok(cb) => cb,
Err(_) => tb.add_class(rt, "Resume")?,
}; Defensive patterns
Strategy: try-catch
Validate before calling
# verify name against known classes assert "Resume" in known_class_names, f"class 'Resume' not defined"
Try / catch
try:
cb = tb.class(name)
except Exception as e:
if "does not exist" in str(e):
cb = tb.add_class(rt, name)
else:
raise Prevention
- 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
When it happens
Trigger: 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).
Common situations: Typo in the class name; calling .class() before add_class(); trying to modify a class registered on a different TypeBuilder instance.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Class {} not found
- Class with name {name} already exists
- Enum with name {name} does not exist
- Class not found: {}
- Property not found: {} in class {}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/f2d991eb882de87d.
Report an issue: GitHub.