BoundaryML/baml · error · StreamingError

Failed to distribute_type_with_meta: {0}

Error message

Failed to distribute_type_with_meta: {0}

What it means

StreamingError::DistributeTypeWithMetaFailure wraps an anyhow error from distribute_type_with_meta via #[from]. Type distribution (choosing/propagating the concrete type with its metadata across the streamed value) failed for an underlying reason such as an unknown enum/class or unresolvable alias.

Source

Thrown at engine/baml-lib/jsonish/src/deserializer/semantic_streaming.rs:28

use indexmap::{IndexMap, IndexSet};
use internal_baml_core::ir::{
    ir_helpers::infer_type_with_meta,
    repr::{IntermediateRepr, Walker},
    Field, IRHelper, IRHelperExtended, IRSemanticStreamingHelper,
};
use thiserror;

use crate::{deserializer::coercer::ParsingError, BamlValueWithFlags, Flag};

#[derive(Debug, thiserror::Error)]
pub enum StreamingError {
    #[error("Expected to encounter a class")]
    ExpectedClass,
    #[error("Value was marked Done, but was incomplete in the stream")]
    IncompleteDoneValue,
    #[error("Class instance did not contain fields marked as needed: {fields:?}")]
    MissingNeededFields { fields: Vec<String> },
    #[error("Failed to distribute_type_with_meta: {0}")]
    DistributeTypeWithMetaFailure(#[from] anyhow::Error),
}

/// For a given baml value, traverse its nodes, comparing the completion state
/// of each node against the streaming behavior of the node's type.
pub fn validate_streaming_state(
    ir: &impl IRHelperExtended,
    baml_value: &BamlValueWithFlags,
    mode: baml_types::StreamingMode,
) -> Result<BamlValueWithMeta<Completion>, StreamingError> {
    let baml_value_with_meta_flags: BamlValueWithMeta<Vec<Flag>> = baml_value.clone().into();
    let typed_baml_value: BamlValueWithMeta<(Vec<Flag>, TypeIR)> =
        ir.distribute_type_with_meta(baml_value_with_meta_flags, baml_value.field_type().clone())?;
    let baml_value_with_streaming_state_and_behavior =
        typed_baml_value.map_meta(|(flags, r#type)| (completion_state(flags), r#type));

    let top_level_node = process_node(
        ir,

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the inner anyhow message (source of this error) to identify which type failed to distribute.
  2. Regenerate the BAML client so the type graph matches the current schema.
  3. Clear cached partial streaming state referencing old type definitions.
  4. Verify all types referenced by the function's return type exist and resolve (enums, classes, aliases).

Example fix

// before: ignoring wrapped cause
if let Err(e) = validate_streaming_state(&v) { log!("{e}"); }
// after: inspect the anyhow source
log!("{e:#}") // prints full chain incl. distribute_type_with_meta cause
Defensive patterns

Strategy: try-catch

Try / catch

match validate_streaming_state(&value) {
    Err(StreamingError::DistributeTypeWithMetaFailure(src)) => {
        log::error!("distribution failed: {src:#}"); // full anyhow chain
        Err(anyhow::anyhow!(src).context("schema/type mismatch during streaming"))
    }
    other => other,
}

Prevention

When it happens

Trigger: Any failure inside distribute_type_with_meta during streaming deserialization — typically because a referenced type (enum, class, alias) could not be resolved against the output format while distributing types over streamed nodes.

Common situations: Schema/client mismatch where generated code references types absent from the runtime output format; recursive alias resolution failing mid-stream; stale partial caches referencing removed types.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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