BoundaryML/baml · error · anyhow::Error
{:?}
Error message
{:?} What it means
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.
Source
Thrown at engine/baml-runtime/src/type_builder/mod.rs:701
let local_ast =
validate_type_builder_entries(&mut diagnostics, &scoped_db, &type_builder_entries);
scoped_db.add_ast(local_ast);
if let Err(d) = scoped_db.validate(&mut diagnostics) {
diagnostics.push(d);
anyhow::bail!("{}", diagnostics.to_pretty_string());
}
run_validation_pipeline_on_db(&mut scoped_db, &mut diagnostics);
if diagnostics.has_errors() {
anyhow::bail!("{}", diagnostics.to_pretty_string());
}
let (classes, enums, type_aliases, recursive_classes, recursive_aliases) =
IntermediateRepr::type_builder_entries_from_scoped_db(&scoped_db, &rt.db)
.map_err(|e| anyhow::anyhow!("{:?}", e))?;
self.add_entries(
&classes
.into_iter()
.map(TypeBuilderEntry::Class)
.chain(enums.into_iter().map(TypeBuilderEntry::Enum))
.chain(type_aliases.into_iter().map(TypeBuilderEntry::TypeAlias))
.collect::<Vec<_>>(),
);
self.recursive_type_aliases()
.lock()
.unwrap()
.extend(recursive_aliases);
self.recursive_classes()
.lock()
.unwrap()View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before
tb.add_baml(`class Node { children Node[] | null }`); // may fail IR lowering in some versions
// after
tb.add_baml(`class NodeChild {}\nclass Node { children (NodeChild | null)[] }`); Defensive patterns
Strategy: try-catch
Try / catch
try {
await tb.add_baml(src);
} catch (e) {
console.error('IR lowering failed:', e.message);
// fall back to a simplified schema or report upstream
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- {diagnostics}
- Type not found for property {} in class {}
- Enum not found: {}
- Enum value already exists: {} in enum {}
- Enum value not found: {} in enum {}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/442ff9d0c14ff557.
Report an issue: GitHub.