BoundaryML/baml · error
Class {} does not have a field: {}
Error message
Class {} does not have a field: {} What it means
After the class resolves, find_existing_class_field looks up the field on the ClassWalker; if find_field returns None it bails with 'Class {} does not have a field: {}'. The referenced field name is absent from an otherwise valid class.
Source
Thrown at engine/baml-lib/jsonish/src/helpers/mod.rs:80
.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<'_>,
) -> Result<Option<(Name, Option<String>)>> {
if enum_walker.is_err() {
anyhow::bail!("Enum {} does not exist", enum_name);
}View on GitHub (pinned to bd85ce9dee)
Solutions
- Correct the field name in the template/helper call to exactly match the class definition.
- Check field case-sensitivity against the .baml class declaration.
- Regenerate clients and search templates for the old field name after renames.
- Consider adding an alias in the schema if the external name must differ.
Example fix
// before
class UserInfo { userName string }
{{ class_userinfo.username }}
// after
{{ class_userinfo.userName }} Defensive patterns
Strategy: validation
Validate before calling
// confirm the field exists before template use
let field_names: Vec<_> = class_walker.find_field_list().iter().map(|f| f.name()).collect();
if !field_names.contains(&field_name.to_string()) {
return Err(anyhow::anyhow!("field '{}' not in class '{}'; available: {:?}", field_name, class_name, field_names));
} Type guard
fn field_exists(w: &ClassWalker, name: &str) -> bool { w.find_field(name).is_some() } 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("fix field name in template to match class definition")),
} Prevention
- Match field names exactly, including case
- Search templates for old field names after schema renames
- Use schema aliases when an external name must differ
When it happens
Trigger: A template/helper references class.field where the class exists but declares no field with that name (case-sensitive), e.g. accessing ctx or description helpers with a stale field name.
Common situations: Renamed or removed class fields while prompts/templates still use the old name; typos in field names; case sensitivity (e.g. 'userName' vs 'username'); dynamic field access built from strings that drifted from the schema.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Class {} does not exist
- Enum {} does not exist
- Failed to get template '{}': {}
- Expected a statically defined string, not expression
- Expected a statically defined string, not a template_string
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/1d730c5a99e20460.
Report an issue: GitHub.