BoundaryML/baml · error · anyhow::Error

Class {name} not found

Error message

Class {name} not found

What it means

OutputFormatContent::find_class looks up a class by (name, StreamingMode) key; a miss becomes this error. It means a class referenced by the output format, jinja template, or streamed response is not in the BAML schema for that streaming mode. The library throws it rather than returning None so the name appears in the propagated error.

Source

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

        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;

    use baml_types::ir_type::UnionConstructor;

    use super::*;

    #[test]

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Verify the class name exists in the .baml schema and matches exactly (case-sensitive).
  2. Regenerate the BAML client after schema edits to sync generated code.
  3. Confirm you pass the correct StreamingMode; check whether the class is only available in streaming or non-streaming form.
  4. Purge cached partial streaming responses keyed to the old schema.

Example fix

// before
let c = output_format.find_class(&mode, "UserExtract")?;
// after: ensure class exists in .baml
// class UserExtract { name string }  ->  baml-cli generate
Defensive patterns

Strategy: validation

Validate before calling

if !output_format.classes.contains_key(&(class_name.to_string(), mode.clone())) {
    return Err(anyhow::anyhow!("class '{}' unavailable in mode {:?}", class_name, mode));
}

Type guard

fn class_exists(of: &OutputFormatContent, mode: &StreamingMode, name: &str) -> bool {
    of.classes.contains_key(&(name.to_string(), mode.clone()))
}

Try / catch

match output_format.find_class(&mode, name) {
    Ok(c) => use_class(c),
    Err(err) => return Err(err.context(format!("check class '{name}' exists in .baml"))),
}

Prevention

When it happens

Trigger: Calling find_class(mode, name) where the classes map has no entry for that (name, mode) pair — e.g. referencing a class in a response before it is defined, or using a streaming-only/non-streaming class in the wrong mode.

Common situations: Streaming mode mismatch (a class registered only for streaming or only for non-streaming); renamed class in the schema while old generated clients persist; typo in class name within a prompt template.

Related errors


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