BoundaryML/baml · error

Class {} already has a pre-defined field: {}

Error message

Class {} already has a pre-defined field: {}

What it means

Runtime new-field overrides may only introduce fields that do not already exist on the BAML class. find_new_class_field bails when the override attempts to add a field the class already defines, since redefining it would create a conflicting schema.

Source

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

        }
    }
}

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());
    let desc = OverridableValue::<String>::from(field_overrides.1.meta.get("description"));

    let name = Name::new_with_alias(field_name.to_string(), alias.value());
    let desc = desc.value();

    Ok(Some((name, field_overrides.0.clone(), desc, false))) // TODO: Field overrides are not "stream.not_null". Should this be configurable?

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Remove the duplicate entry from new_fields — the field already exists on the class
  2. If you intended to modify the existing field, use update_fields instead of new_fields
  3. Reconcile the .baml file with the overrides after schema changes

Example fix

// before
new_fields: { "summary": string }
// after (modify existing field instead)
update_fields: { "summary": { "value": string } }
Defensive patterns

Strategy: validation

Validate before calling

function assertNoFieldCollision(bamlClass, override) {
  for (const name of Object.keys(override.new_fields || {})) {
    if (bamlClass.fields.includes(name))
      throw new Error(`'${name}' already exists on class '${bamlClass.name}'; use update_fields`);
  }
}

Prevention

When it happens

Trigger: A RuntimeClassOverride.new_fields entry names a field that class_walker.find_field already finds on the original class definition.

Common situations: Adding a field via override that was later added to the .baml source (version drift); duplicating an existing field name in the override; stale overrides after refactoring 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


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