BoundaryML/baml · error

Class {} does not have a field: {}

Error message

Class {} does not have a field: {}

What it means

BAML runtime class overrides let clients add new fields to classes at runtime, but only if that override key exists in RuntimeClassOverride.new_fields. find_new_class_field bails when the override references a field name that was never declared in new_fields for the class.

Source

Thrown at engine/baml-runtime/src/internal/prompt_renderer/render_output_format.rs:85

        match v {
            Some(v) => match v.as_str() {
                Some(v) => OverridableValue::Set(v.to_string()),
                None => OverridableValue::SetEmpty,
            },
            None => OverridableValue::Unset,
        }
    }
}

fn find_new_class_field(
    class_name: &str,
    field_name: &str,
    class_walker: &Result<ClassWalker<'_>>,
    overrides: &RuntimeClassOverride,
    _ctx: &RuntimeContext,
) -> Result<Option<(Name, TypeIR, Option<String>, bool)>> {
    let Some(field_overrides) = overrides.new_fields.get(field_name) else {
        anyhow::bail!("Class {} does not have a field: {}", class_name, field_name);
    };

    // Ensure the original field does not exist
    if let Ok(class_walker) = class_walker {
        if class_walker.find_field(field_name).is_some() {
            anyhow::bail!(
                "Class {} already has a pre-defined field: {}",
                class_name,
                field_name
            );
        }
    }

    if let Some(true) = field_overrides.1.skip {
        return Ok(None);
    }

    let alias = OverridableValue::<String>::from(field_overrides.1.alias.as_ref());

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Ensure the new field is added under the class's new_fields map in the runtime override
  2. Verify the class name and field name spelling match exactly
  3. Remove the stale override entry if the field is no longer needed
  4. Regenerate/refresh overrides after renaming fields in the .baml file

Example fix

// before
new_fields: { "descripton": ... }
// after
new_fields: { "description": ... }
Defensive patterns

Strategy: validation

Validate before calling

function assertNewFieldValid(overrides, className, fieldName, existingClass) {
  if (!overrides[className]?.new_fields?.[fieldName])
    throw new Error(`Field '${fieldName}' must be declared in new_fields of class '${className}'`);
  if (existingClass.fields.includes(fieldName))
    throw new Error(`Field '${fieldName}' already exists on class '${className}'`);
}

Prevention

When it happens

Trigger: relevant_data_models encounters a RuntimeClassOverride where a requested new field name is absent from overrides.new_fields while resolving output-format classes.

Common situations: Programmatic override (e.g. via client libraries' output schema overrides) passing a field name that doesn't match the BAML class; typo in the override field key; overrides applied to the wrong class name.

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


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