BoundaryML/baml · error · anyhow::Error

Enum {name} not found

Error message

Enum {name} not found

What it means

OutputFormatContent::find_enum performs a map lookup of enums by name and converts a miss into an anyhow error. It means the LLM response or jinja code referenced an enum that is not present in the BAML schema's output format. The library throws this when rendering or deserializing output that names an unknown enum.

Source

Thrown at engine/baml-lib/jinja-runtime/src/output_format/types.rs:1068

    }
}

#[cfg(test)]
impl OutputFormatContent {
    pub fn new_array() -> Self {
        Self::target(TypeIR::List(Box::new(TypeIR::string()), Default::default())).build()
    }

    pub fn new_string() -> Self {
        Self::target(TypeIR::string()).build()
    }
}

impl OutputFormatContent {
    pub fn find_enum(&self, name: &str) -> Result<&Enum> {
        self.enums
            .get(name)
            .ok_or_else(|| anyhow::anyhow!("Enum {name} not found"))
    }

    pub fn find_class(&self, mode: &baml_types::StreamingMode, name: &str) -> Result<&Class> {
        self.classes
            .get(&(name.to_string(), *mode))
            .ok_or_else(|| anyhow::anyhow!("Class {name} not found"))
    }

    pub fn find_recursive_alias_target(&self, name: &str) -> Result<&TypeIR> {
        self.structural_recursive_aliases
            .get(name)
            .ok_or_else(|| anyhow::anyhow!("Recursive alias {name} not found"))
    }
}

#[cfg(test)]
mod tests {
    use std::vec;

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Check the enum name spelling against the enums declared in your .baml schema.
  2. Regenerate the BAML client (baml-cli generate) after any schema change so generated code matches the schema.
  3. Invalidate any cached or persisted partial LLM responses that reference the old enum name.
  4. Wrap find_enum calls or error-propagated paths in error handling that surfaces the missing enum name to the user.

Example fix

// before: schema no longer declares this enum
let e = output_format.find_enum("Sentiment")?;
// after: add to .baml and regenerate
// enum Sentiment { POSITIVE NEGATIVE }  ->  baml-cli generate
Defensive patterns

Strategy: validation

Validate before calling

// rust: before consuming streamed output
let known: std::collections::HashSet<&str> = output_format.enums.keys().map(|s| s.as_str()).collect();
if !known.contains(referenced_enum) {
    return Err(anyhow::anyhow!("schema drift: enum '{}' not in output format", referenced_enum));
}

Type guard

fn enum_exists(of: &OutputFormatContent, name: &str) -> bool { of.enums.contains_key(name) }

Try / catch

match output_format.find_enum(name) {
    Ok(e) => use_enum(e),
    Err(err) => log::error!("enum lookup failed: {err:#}"),
}

Prevention

When it happens

Trigger: Calling find_enum(name) when no enum with that name exists in the current OutputFormatContent — e.g. the LLM streamed an enum name not declared in the BAML schema, or the schema was changed/renamed between runs.

Common situations: Renaming or deleting an enum in a .baml file while cached/persisted partial responses still reference the old name; typos in enum names inside prompt templates; stale client binaries out of sync with the server-side schema.

Related errors


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