{"record":{"id":"442ff9d0c14ff557","repo":"BoundaryML/baml","slug":"mod","errorCode":null,"errorMessage":"{:?}","messagePattern":"\\{:\\?\\}","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/type_builder/mod.rs","lineNumber":701,"sourceCode":"\n        let local_ast =\n            validate_type_builder_entries(&mut diagnostics, &scoped_db, &type_builder_entries);\n        scoped_db.add_ast(local_ast);\n\n        if let Err(d) = scoped_db.validate(&mut diagnostics) {\n            diagnostics.push(d);\n            anyhow::bail!(\"{}\", diagnostics.to_pretty_string());\n        }\n\n        run_validation_pipeline_on_db(&mut scoped_db, &mut diagnostics);\n\n        if diagnostics.has_errors() {\n            anyhow::bail!(\"{}\", diagnostics.to_pretty_string());\n        }\n\n        let (classes, enums, type_aliases, recursive_classes, recursive_aliases) =\n            IntermediateRepr::type_builder_entries_from_scoped_db(&scoped_db, &rt.db)\n                .map_err(|e| anyhow::anyhow!(\"{:?}\", e))?;\n\n        self.add_entries(\n            &classes\n                .into_iter()\n                .map(TypeBuilderEntry::Class)\n                .chain(enums.into_iter().map(TypeBuilderEntry::Enum))\n                .chain(type_aliases.into_iter().map(TypeBuilderEntry::TypeAlias))\n                .collect::<Vec<_>>(),\n        );\n\n        self.recursive_type_aliases()\n            .lock()\n            .unwrap()\n            .extend(recursive_aliases);\n\n        self.recursive_classes()\n            .lock()\n            .unwrap()","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/type_builder/mod.rs#L683-L719","documentation":"Once validation passes, add_baml() asks IntermediateRepr::type_builder_entries_from_scoped_db to lower the validated scoped DB into runtime entries (classes, enums, aliases). If the IR lowering returns an error, it is formatted with {:?} and rethrown. This indicates the DB validated but could not be converted into the intermediate representation — typically an internal edge case rather than a user syntax problem.","triggerScenarios":"type_builder.add_baml(...) where IR conversion from the scoped DB fails, e.g. entries that survive validation but reference types from the base DB in ways the IR lowering cannot resolve (recursive or exotic constructs).","commonSituations":"Highly dynamic schemas combining recursive classes/aliases with base-project types; version mismatches where the CLI/runtime IR changed; constructs rarely exercised in type builders.","solutions":["Read the Debug-formatted inner error ({:?}) — it identifies which entry failed IR lowering.","Simplify the snippet: remove recursion or unusual type aliases and re-add them one at a time.","Ensure your BAML CLI and runtime library versions match (mismatched IR formats can break lowering).","If the construct looks valid, report it to the BAML repo with the snippet and stack trace — this path is usually reached only via internal edge cases."],"exampleFix":"// before\ntb.add_baml(`class Node { children Node[] | null }`); // may fail IR lowering in some versions\n// after\ntb.add_baml(`class NodeChild {}\\nclass Node { children (NodeChild | null)[] }`);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await tb.add_baml(src);\n} catch (e) {\n  console.error('IR lowering failed:', e.message);\n  // fall back to a simplified schema or report upstream\n}","preventionTips":["Keep baml CLI and runtime package versions in lockstep.","Avoid exotic recursive/intersection constructs in dynamic type builders until tested.","Test type_builder snippets in CI so IR lowering failures surface before production."],"tags":["baml","internal-repr","type-builder","lowering"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}