BoundaryML/baml · error

{s:?}

Error message

{s:?}

What it means

During streaming response assembly, parsed_value_to_response runs validate_streaming_state to confirm the partially streamed value is consistent with the function's IR and streaming mode. When validation fails, the returned error is a debug-formatted (:) list of streaming-state problem strings, wrapped with anyhow. It indicates the streamed partial output cannot be reconciled into a valid partial BAML value.

Source

Thrown at engine/baml-runtime/src/internal/llm_client/mod.rs:58

        baml_value.clone().into();
    let meta_field_type: BamlValueWithMeta<TypeIR> = baml_value.clone().into();

    let value_with_response_checks: BamlValueWithMeta<Vec<ResponseCheck>> = baml_value_with_meta
        .map_meta(|cs| {
            cs.iter()
                .map(|(label, expr, result)| {
                    let status = (if *result { "succeeded" } else { "failed" }).to_string();
                    ResponseCheck {
                        name: label.clone(),
                        expression: expr.0.clone(),
                        status,
                    }
                })
                .collect()
        });

    let baml_value_with_streaming =
        validate_streaming_state(ir, &baml_value, mode).map_err(|s| anyhow::anyhow!("{s:?}"))?;

    // Combine the baml_value, its types, the parser flags, and the streaming state
    // into a final value.
    // Node that we set the StreamState to `None` unless `allow_partials`.
    let response_value = baml_value_with_streaming
        .zip_meta(&value_with_response_checks)?
        .zip_meta(&meta_flags)?
        .zip_meta(&meta_field_type)?
        .map_meta(|(((x, y), z), ft)| {
            jsonish::ResponseValueMeta(z.clone(), y.clone(), x.clone(), ft.clone())
        });
    Ok(ResponseBamlValue(response_value))
}

// Whether we should download a url into a base64 (resolving it if necessary), as well as
// whether we should add the mime type, etc.
#[derive(Clone, Copy, PartialEq)]
pub enum ResolveMediaUrls {

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the debug-formatted list in the message — it enumerates each invalid streaming-state entry
  2. Regenerate the BAML client so IR and parser agree on the output schema
  3. Ensure the stream chunk passed to the parser is complete/consistent (not arbitrarily truncated mid-token in a way the parser rejects)
  4. If partials are not needed, disable allow_partials so incomplete values are not validated as partials

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// Check stream shape/schema agreement before parsing partials
if output_schema_changed {
    regen_client(); // ensure IR matches streamed value types
}

Try / catch

match validate_stream_result(raw_stream) {
    Ok(v) => v,
    Err(e) => {
        // message contains a debug list of invalid streaming states
        log::warn!("streaming state invalid: {e}");
        fall_back_to_non_streaming_call()
    }
}

Prevention

When it happens

Trigger: Calling to_response / parsed_value_to_response (e.g. via stable_keys2) on a streamed BAML value where mode allows partials but the partial state is invalid — e.g. required fields missing in an in-progress object that cannot legally be partial, malformed enum/class matches mid-stream, or mismatches between the parsed value shape and the IR's expected output type.

Common situations: Custom streaming parsers or partially consumed stream chunks fed back into the runtime; output schema changes without regenerating the client so the streamed shape no longer matches the IR; feeding truncated LLM output into partial parsing with allow_partials enabled.

Related errors


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