BoundaryML/baml · error

Enum not found

Error message

Enum not found: {}

What it means

Thrown by EnumBuilder::enm(), the resolver used by add_value, set_description, set_alias, alias, description and type_. If the enum is not in the runtime IR, the builder looks in the type-builder graph via maybe_get_enum; when it's absent from both, it bails with 'Enum not found'. You are operating on an enum that exists nowhere.

Solutions

  1. Define the enum in the .baml schema, or upsert it first with tb.enum_("Color") and add at least one value.
  2. Correct the enum name spelling to match the schema.
  3. Verify the enum wasn't renamed/removed in recent .baml changes.
  4. Ensure you're using the same TypeBuilder/BamlRuntime the enum was registered on.

Example fix

// before
tb.enum("Collar").add_value(rt, "red")?; // enum 'Collar' doesn't exist
// after
tb.enum("Color").add_value(rt, "red")?;
Defensive patterns

Strategy: validation

Validate before calling

if rt.ir.find_enum("Color").is_err() {
    // upsert the enum and add values before calling add_value/description/alias
    tb.enum_("Color");
}

Try / catch

match enum_builder.add_value(rt, "red") {
    Err(e) if e.to_string().starts_with("Enum not found") => define_enum_first()?,
    other => other,
}

Prevention

When it happens

Trigger: Calling tb.enum_("Color").add_value(...)/description(...)/alias(...) where enum Color is neither defined in any .baml file nor upserted via tb.enum_(...) with add_value in the current type builder.

Common situations: typos in the enum name; referencing an enum removed or renamed in the schema; building an enum dynamically but calling value-level methods before any registration; wrong 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


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

Appendix: source

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

            mode: NodeRW::ReadOnly,
        }
    }

    fn mode(self, mode: NodeRW) -> Self {
        Self { mode, ..self }
    }

    fn enm(
        &self,
        rt: &BamlRuntime,
    ) -> anyhow::Result<std::sync::Arc<std::sync::Mutex<type_builder::EnumBuilder>>> {
        // if the IR defines the enum, then its always valid
        if rt.ir.find_enum(self.enum_name.as_str()).is_ok() {
            return Ok(self.type_builder.upsert_enum(self.enum_name.as_str()));
        }

        let Some(enm) = self.type_builder.maybe_get_enum(self.enum_name.as_str()) else {
            anyhow::bail!("Enum not found: {}", self.enum_name);
        };
        Ok(enm)
    }

    fn create_value(&self, name: &str, rt: &BamlRuntime) -> EnumValueBuilder {
        let target_mode = match self.mode {
            NodeRW::ReadOnly => NodeRW::ReadOnly,
            NodeRW::LLMOnly => NodeRW::LLMOnly,
            NodeRW::ReadWrite => {
                if let Ok(enm) = rt.ir.find_enum(self.enum_name.as_str()) {
                    if enm.find_value(name).is_some() {
                        NodeRW::LLMOnly
                    } else {
                        NodeRW::ReadWrite
                    }
                } else {
                    NodeRW::ReadWrite
                }

View on GitHub (pinned to bd85ce9dee)