BoundaryML/baml · error
Class {} does not exist
Error message
Class {} does not exist What it means
find_existing_class_field receives a ClassWalker wrapped in a Result; if the walker itself is an Err (the class could not be resolved in the codebase), it bails with 'Class {} does not exist'. This is used when resolving fields referenced from jinja helpers/templates against the BAML data model.
Source
Thrown at engine/baml-lib/jsonish/src/helpers/mod.rs:76
streaming_mode == baml_types::StreamingMode::Streaming,
)?;
Ok(OutputFormatContent::target(output.clone())
.enums(enums)
.classes(classes)
.recursive_classes(recursive_classes)
.structural_recursive_aliases(structural_recursive_aliases)
.build())
}
fn find_existing_class_field(
class_name: &str,
field_name: &str,
class_walker: &Result<ClassWalker<'_>>,
env_values: &EvaluationContext<'_>,
) -> Result<(Name, TypeIR, Option<String>, bool)> {
let Ok(class_walker) = class_walker else {
anyhow::bail!("Class {} does not exist", class_name);
};
let Some(field_walker) = class_walker.find_field(field_name) else {
anyhow::bail!("Class {} does not have a field: {}", class_name, field_name);
};
let name = Name::new_with_alias(field_name.to_string(), field_walker.alias(env_values)?);
let desc = field_walker.description(env_values)?;
let r#type = field_walker.r#type();
let streaming_needed = field_walker.item.attributes.streaming_behavior().needed;
Ok((name, r#type.clone(), desc, streaming_needed))
}
fn find_enum_value(
enum_name: &str,
value_name: &str,
enum_walker: &Result<EnumWalker<'_>>,
env_values: &EvaluationContext<'_>,View on GitHub (pinned to bd85ce9dee)
Solutions
- Fix the class name in the template/helper call to match a class declared in your .baml files.
- Search your project for the class definition and confirm it is in a loaded .baml file.
- Regenerate clients/templates after renames so references stay in sync.
- Pre-validate referenced class names in CI (e.g. run baml-cli to surface unresolvable references).
Example fix
// before: template references wrong class
{{ ctx.classes["UsrInfo"].name }}
// after
{{ ctx.classes["UserInfo"].name }} Defensive patterns
Strategy: validation
Validate before calling
// before invoking template helpers that resolve classes
let class_walker = env.find_class(class_name);
if class_walker.is_err() {
return Err(anyhow::anyhow!("template references unknown class '{}' — check .baml files", class_name));
} Type guard
fn class_resolves(env: &FunctionCfg, name: &str) -> bool { env.find_class(name).is_ok() } Try / catch
match find_existing_class_field(class_name, field_name, &class_walker, &env) {
Ok(v) => use_field(v),
Err(err) => return Err(err.context("template references a class not defined in .baml")),
} Prevention
- Reference classes in templates only by names that exist in loaded .baml files
- Run baml-cli validation in CI to catch unresolvable references
- Grep templates after class renames
When it happens
Trigger: relevant_data_models calls find_existing_class_field with class_walker = env.find_class/class_walker(name) that returned Err — i.e. the class name in a template helper (e.g. a field-description lookup) has no matching class in the BAML sources.
Common situations: Typos in class names inside jinja templates (e.g. ctx.output_format / description helpers); classes deleted or renamed while templates still reference them; multi-file BAML projects where the class lives in a file not loaded.
Related errors
- Class {name} not found
- Class {} does not have a field: {}
- Enum {} does not exist
- Class '{0}' not found
- Could not unify Class {} with {:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/46d5f9ce4a58ee80.
Report an issue: GitHub.