BoundaryML/baml · error · ConvertError

Unknown class

Error message

Unknown class: {0}

What it means

ConvertError::UnknownClass(DefKey) is declared in the SAP model conversion error enum. It represents a type reference to a class name that cannot be found among the registered class definitions when resolving SAP model types.

Solutions

  1. Verify the class name in the error is declared and spelled correctly in your BAML sources.
  2. Ensure the module/file containing the class is included in the compilation context passed to TypeCtx (SysOpContext.class_definitions).
  3. Rebuild/regenerate the SAP model after adding the missing class definition.

Example fix

// before
function Extract() -> MissingClass
// after
class MissingClass { name: string }
function Extract() -> MissingClass
Defensive patterns

Strategy: validation

Validate before calling

// Verify every referenced class name exists before conversion
fn class_exists(ctx: &TypeCtx, key: &DefKey) -> bool {
    ctx.class_definitions.contains_key(key)
}

Try / catch

match result {
    Err(ConvertError::UnknownClass(key)) => eprintln!("declare class {key:?} or fix its spelling"),
    other => other,
}

Prevention

When it happens

Trigger: Resolving a class-typed reference whose DefKey has no entry in TypeCtx::class_definitions — i.e. the referenced class was never declared or was pruned from the context before build_db.

Common situations: A BAML file references a class defined in another module that was not loaded; a typo in a class name; a class removed in a refactor while aliases or fields still reference it.

Related errors


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

Appendix: source

Thrown at baml_language/crates/bex_sap/src/sap_model/convert.rs:32

    self, AnnotatedEnumVariant, AnnotatedField, AnnotatedTy, ArrayTy, AttrLiteral, BigintLiteralTy,
    BigintTy, BoolLiteralTy, BoolTy, ClassTy, EnumTy, EnumVariantTy, FloatTy, IntLiteralTy, IntTy,
    MapTy, MediaTy, NullTy, StringLiteralTy, StringTy, TyResolved, TyWithMeta, TypeAnnotations,
    TypeRefDb, UnionTy,
};

impl crate::sap_model::TypeIdent for DefKey {}

#[derive(thiserror::Error, Debug)]
pub enum ConvertError {
    #[error("Failed to parse float: {0}")]
    ParseFloat(#[from] std::num::ParseFloatError),
    #[error("Unknown media kind")]
    UnknownMediaKind,
    #[error("Float literals cannot be parsed")]
    FloatLiteral,
    #[error("Non-parsable type: {0:?}")]
    NonParsableType(Box<SapTy>),
    #[error("Unknown class: {0}")]
    UnknownClass(DefKey),
    #[error("Unknown enum: {0}")]
    UnknownEnum(DefKey),
    #[error("Unknown type alias: {0}")]
    UnknownTypeAlias(DefKey),
    #[error("Unknown name (could not determine if it was a class, enum, or type alias): {0}")]
    UnknownName(DefKey),
    #[error("Could not add a type to the database as the name `{0}` is already present")]
    AlreadyPresent(DefKey),
    #[error("Recursion depth exceeded for {0}")]
    RecursionDepthExceeded(&'static str),
    #[error("Unions must be flattened")]
    UnflattenedUnion,
    /// Something like `type A = B; type B = A;` is invalid.
    #[error("Recursive type alias without indirection: {0}")]
    DirectRecursiveTypeAlias(DefKey),
    #[error("Internal error (please report): {0}")]
    InternalError(&'static str),

View on GitHub (pinned to bd85ce9dee)