BoundaryML/baml · error · ConvertError

Non-parsable type: {0:?}

Error message

Non-parsable type: {0:?}

What it means

ConvertError::NonParsableType is raised while converting BAML types to the SAP model in bex_sap. The named type (class/interface/alias) or leaf type (Uint8Array, Resource, PromptAst, Function, Void, Unknown, Future, TypeVar, AssociatedTypeProjection, Never, RustType, Type) has no SAP-parsable representation. The library pre-computes which names are SAP-parsable in TypeCtx::new and refuses to emit them into the TypeRefDb.

Source

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

use crate::sap_model::{
    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),

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Find the type shown in the error and replace the unparsable leaf (Uint8Array, Resource, Future, TypeVar, etc.) with a SAP-supported type such as string, int, bool, list, or map.
  2. If it is a class reference, check the referenced class's fields — one of them is unparsable and makes the whole reference unparsable; fix or skip that field (fields marked skip are excluded).
  3. If a generic TypeVar is involved, ensure it was substituted with a concrete SAP-parsable type before materializing the parse target (see TypeCtx::normalize_parse_target).
  4. If the type should be SAP-parsable but is not, report it as a possible gap in bex_sap's type coverage.

Example fix

// before (BAML)
class Attachment { data: uint8array }
// after
class Attachment { data: string } // base64-encode instead of raw bytes
Defensive patterns

Strategy: validation

Validate before calling

// Before building the SAP model, ensure no field/alias uses unparsable leaves
fn validate_sap_parsable(ctx: &TypeCtx) -> Result<(), String> {
    // TypeCtx already computes this: names with sap_parseable == false are excluded
    for (name, ok) in &ctx.sap_parseable {
        if !ok { return Err(format!("type {name:?} is not SAP-parsable")); }
    }
    Ok(())
}

Type guard

fn is_sap_parsable_leaf(ty: &SapTy) -> bool {
    !matches!(ty, SapTy::Uint8Array{..} | SapTy::Resource{..} | SapTy::PromptAst{..} | SapTy::Function{..} | SapTy::Void{..} | SapTy::Unknown{..} | SapTy::Future(..) | SapTy::TypeVar(..) | SapTy::Never{..})
}

Prevention

When it happens

Trigger: Calling TypeCtx::build_db (directly or via from_sys_op_context) when a class field or type alias references a type where is_sap_parseable fails (e.g. SapTy::Uint8Array, SapTy::Resource, SapTy::Future, SapTy::TypeVar) or a class/alias whose sap_parseable check returned false.

Common situations: BAML schemas containing media/resource-backed fields, generic type variables not yet substituted, futures or internal Rust types leaking into a SAP-facing type, or a class referencing another class that itself has an unparsable field.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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