BoundaryML/baml · error
Enum {} not found
Error message
Enum {} not found What it means
find_enum in ScopedIR fails when the requested enum name is absent from the IR and no RuntimeEnumOverride exists. Same resolution model as find_class: only a static BAML definition or a dynamic override satisfies the lookup.
Source
Thrown at engine/baml-runtime/src/internal/prompt_renderer/scoped_ir.rs:55
let class = self.ir.find_class(class_name);
match (class, class_override) {
(Err(_), None) => Err(anyhow::anyhow!("Class {} not found", class_name)),
(Ok(class), None) => Ok(FindResult::OnlyIr(class)),
(Err(_), Some(class_override)) => Ok(FindResult::OnlyDynamic(class_override)),
(Ok(class), Some(class_override)) => Ok(FindResult::Overriden(class, class_override)),
}
}
fn find_enum(
&self,
enum_name: &str,
) -> Result<FindResult<internal_baml_core::ir::EnumWalker<'ir>, &RuntimeEnumOverride>> {
let enum_override = self.ctx.enum_overrides.get(enum_name);
let r#enum = self.ir.find_enum(enum_name);
match (r#enum, enum_override) {
(Err(_), None) => Err(anyhow::anyhow!("Enum {} not found", enum_name)),
(Ok(r#enum), None) => Ok(FindResult::OnlyIr(r#enum)),
(Err(_), Some(enum_override)) => Ok(FindResult::OnlyDynamic(enum_override)),
(Ok(r#enum), Some(enum_override)) => Ok(FindResult::Overriden(r#enum, enum_override)),
}
}
}
impl IRSemanticStreamingHelper for ScopedIr<'_> {
fn class_streaming_needed_fields(
&self,
class_name: &str,
) -> Result<std::collections::HashSet<String>> {
let class_type = &self.find_class(class_name)?;
let result = match class_type {
FindResult::OnlyIr(cls) | FindResult::Overriden(cls, _) => cls
.walk_fields()
.filter_map(|field| {
if field.streaming_behavior().needed {View on GitHub (pinned to bd85ce9dee)
Solutions
- Declare the enum in a .baml file or correct the spelling of its name.
- Provide a RuntimeEnumOverride in RuntimeContext.enum_overrides for dynamically defined enums.
- Regenerate the BAML client so the IR includes recent schema changes.
- Confirm the enum's file is included in the BAML source directory.
Example fix
// before (baml)
class Output {
cat Catgory
}
// after
enum Category { A B }
class Output {
cat Category
} Defensive patterns
Strategy: try-catch
Validate before calling
if scoped.find_enum(enum_name).is_err() {
eprintln!("Enum {} missing from BAML schema", enum_name);
} Type guard
fn enum_resolves(scoped: &ScopedIr, name: &str) -> bool {
scoped.find_enum(name).is_ok()
} Try / catch
let ew = scoped.find_enum(enum_name)
.with_context(|| format!("Check .baml files for enum {}", enum_name))?; Prevention
- Run baml-cli check as a pre-commit hook.
- Rename enums with tooling so all references update together.
- Register RuntimeEnumOverrides for any dynamically supplied enums.
When it happens
Trigger: Prompt/output rendering resolves an enum type name that no .baml file declares and RuntimeContext has no enum_overrides entry for it.
Common situations: Misspelled enum name; enum renamed/removed; enum file outside baml_src; using dynamic schema overrides but forgetting to register the enum override.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Enum {} does not exist
- Class {} not found
- Enum with name {name} does not exist
- function `{function_name}` not found
- function `{target_name}` not found
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/87a646459b09d5e3.
Report an issue: GitHub.