BoundaryML/baml · error
Class {} not found
Error message
Class {} not found What it means
find_class in ScopedIR fails when the requested class name is absent from the IR and there is no RuntimeClassOverride. ScopedIR resolves names for prompt/output rendering; with neither a static definition nor a dynamic override the class cannot be resolved, so rendering aborts.
Source
Thrown at engine/baml-runtime/src/internal/prompt_renderer/scoped_ir.rs:40
}
impl<'ir> ScopedIr<'ir> {
pub fn new(
ir: &'ir internal_baml_core::ir::repr::IntermediateRepr,
ctx: &'ir RuntimeContext,
) -> Self {
Self { ir, ctx }
}
fn find_class(
&self,
class_name: &str,
) -> Result<FindResult<internal_baml_core::ir::ClassWalker<'ir>, &RuntimeClassOverride>> {
let class_override = self.ctx.class_override.get(class_name);
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)),View on GitHub (pinned to bd85ce9dee)
Solutions
- Define the class in a .baml file within the project, or fix the name typo.
- If the class is dynamic (tests/evals), supply a RuntimeClassOverride via the RuntimeContext.
- Regenerate the client (baml-cli generate) so the runtime IR is current.
- Verify the .baml file containing the class is inside the baml_src directory.
Example fix
// before
scoped.find_class("Outpt")?; // typo
// after
scoped.find_class("Output")?; Defensive patterns
Strategy: try-catch
Validate before calling
if scoped.find_class(class_name).is_err() {
eprintln!("Class {} missing from BAML schema", class_name);
} Type guard
fn class_resolves(scoped: &ScopedIr, name: &str) -> bool {
scoped.find_class(name).is_ok()
} Try / catch
match scoped.find_class(class_name) {
Ok(result) => render(result),
Err(e) if e.to_string().contains("not found") => {
// fall back to defaults or fix schema
}
Err(e) => return Err(e),
} Prevention
- Generate types with baml-cli generate so compile-time checks catch missing classes.
- Never hard-code class name strings; derive them from generated constants.
- Verify class files live under baml_src and are committed.
When it happens
Trigger: Calling render_output_format / prompt rendering with a class (response model) name that does not exist in any loaded .baml file and has no class override in RuntimeContext.
Common situations: Typo in the class name; class deleted or renamed; class defined in a .baml file not picked up by the BAML project; invoking a function whose output type was removed; client-side dynamic classes not passed as overrides.
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 {} not found
- Class with name {name} does not exist
- function `{function_name}` not found
- function `{target_name}` not found
- Schema inconsistency: {message}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/749e728ef27518be.
Report an issue: GitHub.