{"record":{"id":"98616b7a15080991","repo":"BoundaryML/baml","slug":"class-already-has-a-pre-defined-field","errorCode":null,"errorMessage":"Class {} already has a pre-defined field: {}","messagePattern":"Class (.+?) already has a pre-defined field: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/prompt_renderer/render_output_format.rs","lineNumber":91,"sourceCode":"        }\n    }\n}\n\nfn find_new_class_field(\n    class_name: &str,\n    field_name: &str,\n    class_walker: &Result<ClassWalker<'_>>,\n    overrides: &RuntimeClassOverride,\n    _ctx: &RuntimeContext,\n) -> Result<Option<(Name, TypeIR, Option<String>, bool)>> {\n    let Some(field_overrides) = overrides.new_fields.get(field_name) else {\n        anyhow::bail!(\"Class {} does not have a field: {}\", class_name, field_name);\n    };\n\n    // Ensure the original field does not exist\n    if let Ok(class_walker) = class_walker {\n        if class_walker.find_field(field_name).is_some() {\n            anyhow::bail!(\n                \"Class {} already has a pre-defined field: {}\",\n                class_name,\n                field_name\n            );\n        }\n    }\n\n    if let Some(true) = field_overrides.1.skip {\n        return Ok(None);\n    }\n\n    let alias = OverridableValue::<String>::from(field_overrides.1.alias.as_ref());\n    let desc = OverridableValue::<String>::from(field_overrides.1.meta.get(\"description\"));\n\n    let name = Name::new_with_alias(field_name.to_string(), alias.value());\n    let desc = desc.value();\n\n    Ok(Some((name, field_overrides.0.clone(), desc, false))) // TODO: Field overrides are not \"stream.not_null\". Should this be configurable?","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/prompt_renderer/render_output_format.rs#L73-L109","documentation":"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.","triggerScenarios":"A RuntimeClassOverride.new_fields entry names a field that class_walker.find_field already finds on the original class definition.","commonSituations":"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.","solutions":["Remove the duplicate entry from new_fields — the field already exists on the class","If you intended to modify the existing field, use update_fields instead of new_fields","Reconcile the .baml file with the overrides after schema changes"],"exampleFix":"// before\nnew_fields: { \"summary\": string }\n// after (modify existing field instead)\nupdate_fields: { \"summary\": { \"value\": string } }","handlingStrategy":"validation","validationCode":"function assertNoFieldCollision(bamlClass, override) {\n  for (const name of Object.keys(override.new_fields || {})) {\n    if (bamlClass.fields.includes(name))\n      throw new Error(`'${name}' already exists on class '${bamlClass.name}'; use update_fields`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After adding a field to .baml, delete any override that adds the same field","Adopt the convention: new fields -> new_fields, modifications -> update_fields","Run schema/override consistency checks in CI"],"tags":["baml","schema","override","conflict"],"backgroundTag":"schema-validation-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}