BoundaryML/baml · error
Enum with name {name} does not exist
Error message
Enum with name {name} does not exist What it means
TypeBuilder::r#enum looks up an existing enum builder by name. If the enum exists in the runtime IR but was not registered on this TypeBuilder (maybe_get_enum returns None), or does not exist at all, the lookup bails with this error.
Source
Thrown at engine/language_client_cffi/src/raw_ptr_wrapper/type_builder/objects.rs:123
}
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(),
name.to_string(),
)),
None => {
anyhow::bail!("Enum with name {name} does not exist");
}
},
}
}
pub fn add_baml(&self, baml: &str, rt: &BamlRuntime) -> anyhow::Result<()> {
self.type_builder.add_baml(baml, rt)
}
pub fn list_enums(&self, rt: &BamlRuntime) -> Vec<EnumBuilder> {
let ir = &rt.ir;
let enums = ir.walk_enums();
enums
.map(|enm| enm.name().to_string())
.chain(self.type_builder.list_enums())
.collect::<indexmap::IndexSet<_>>()
.into_iter()
.map(|name| EnumBuilder::new(self.type_builder.clone(), name))View on GitHub (pinned to bd85ce9dee)
Solutions
- Add the enum first with tb.add_enum(rt, name) before lookup
- Verify the enum name matches the BAML declaration exactly
- Use the same TypeBuilder instance for add and lookup
Example fix
// before
let eb = tb.r#enum(rt, "Colr")?; // typo -> does not exist
// after
let eb = match tb.r#enum(rt, "Color") {
Ok(eb) => eb,
Err(_) => tb.add_enum(rt, "Color")?,
}; Defensive patterns
Strategy: try-catch
Validate before calling
# verify name against known enums assert "Color" in known_enum_names, f"enum 'Color' not defined"
Try / catch
try:
eb = tb.enum(name)
except Exception as e:
if "does not exist" in str(e):
eb = tb.add_enum(rt, name)
else:
raise Prevention
- Call add_enum before any lookup of a dynamic enum
- Verify enum names against the compiled BAML IR
- Keep TypeBuilder construction and lookup in the same scope
When it happens
Trigger: Calling tb.r#enum(rt, "Name") for an enum name that is neither in the runtime IR nor registered on this TypeBuilder (typo or never added via add_enum).
Common situations: Typo in enum name; calling .r#enum() before add_enum(); using a different TypeBuilder instance than the one the enum was added to.
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
- Enum {} not found
- Enum with name {name} already exists
- Class with name {name} does not exist
- Enum '{0}' not found
- Enum {name} not found
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/05be22691c2e9973.
Report an issue: GitHub.