BoundaryML/baml · error
undefined field: {class_name}.{field}
Error message
undefined field: {class_name}.{field} What it means
This is a Rust panic raised during bytecode generation in the BAML compiler's codegen pass. When compiling an assignment to an instance field (obj.field = value), the compiler resolved the base's class type but the field name was not found in the class's resolved field map. It means the field name in your BAML source does not exist on the declared class.
Source
Thrown at engine/baml-compiler/src/codegen.rs:604
thir::Statement::Assign { left, value, .. } => {
match left {
thir::Expr::Var(name, _) => {
self.compile_expression_with_block_behavior(value, true);
self.emit(Instruction::StoreVar(self.locals[name]));
}
thir::Expr::FieldAccess { base, field, meta: _ } => {
// Get class name from type metadata
let class_name = match base.meta().1.as_ref() {
Some(TypeIR::Class { name, .. }) => name,
_ => panic!("Field access on non-class type"),
};
// Resolve field index
let Some(resolved_fields) = self.classes.get(class_name) else {
panic!("undefined class: {class_name}");
};
let Some(&field_index) = resolved_fields.get(field) else {
panic!("undefined field: {class_name}.{field}");
};
// Generate bytecode: load base, load value, store field
self.compile_expression(base);
self.compile_expression_with_block_behavior(value, true);
self.emit(Instruction::StoreField(field_index));
}
thir::Expr::ArrayAccess {base, index, meta: _} => {
self.compile_expression(base);
self.compile_expression(index);
self.compile_expression_with_block_behavior(value, true);
self.emit(match base.meta().1.as_ref().expect("must have a resolved type") {
TypeIR::List(_, _) => Instruction::StoreArrayElement,
TypeIR::Map(_, _, _) => Instruction::StoreMapElement,
_ => panic!("array access should be either map or array.")
});View on GitHub (pinned to bd85ce9dee)
Solutions
- Fix the field name in the BAML source to match the class definition
- Check the class declaration for the exact field spelling/casing
- Regenerate the IR if the class was recently edited so type metadata is fresh
Example fix
// before obj.nmae = "x" // after obj.name = "x"
Defensive patterns
Strategy: validation
Validate before calling
fn validate_field(class_fields: &[&str], class_name: &str, field: &str) -> Result<(), String> {
if !class_fields.contains(&field) {
return Err(format!("field '{}' does not exist on class '{}'", field, class_name));
}
Ok(())
} Prevention
- Keep field names in assignments consistent with class declarations
- Grep BAML sources for the field name after renames
- Run compilation early in CI to catch field typos
When it happens
Trigger: Compiling a BAML statement like `obj.field = value` where `field` is not a member of the class of `obj`; misspelled field name; assigning a field on the wrong class instance.
Common situations: Typos in BAML source; renaming a class field without updating assignments; generated code drift after class schema edits.
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
- array access should be either map or array.
- undefined function: {name}
- watch codegen error: undefined variable: {variable}
- sys_op callee must resolve to a statically-known global func
- expected jump instruction at index {instruction_idx}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/c937da922a3ea076.
Report an issue: GitHub.