BoundaryML/baml · error · StreamingError
Value was marked Done, but was incomplete in the stream
Error message
Value was marked Done, but was incomplete in the stream
What it means
StreamingError::IncompleteDoneValue indicates a value in the stream was marked Done (complete) but its content is not actually parseable as a complete value. The streaming state machine's Done marker disagrees with the actual data, so validation fails rather than silently returning truncated output.
Source
Thrown at engine/baml-lib/jsonish/src/deserializer/semantic_streaming.rs:24
use anyhow::{Context, Error};
use baml_types::{
BamlMap, BamlValueWithMeta, Completion, CompletionState, ResponseCheck, TypeIR, TypeValue,
};
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 =View on GitHub (pinned to bd85ce9dee)
Solutions
- Re-run the request with a higher max_tokens / output budget.
- Enable partial streaming parsing and validate completeness before treating the value as final.
- Check stop sequences and provider settings that may terminate generation early.
- Retry the request; if reproducible, inspect whether your proxy/client truncates streams.
Example fix
// before: treating final chunk as complete
let value = parse_done(chunk)?;
// after: guard
match validate_streaming_state(&value) {
Err(StreamingError::IncompleteDoneValue) => retry_or_request_continuation(),
other => other?,
} Defensive patterns
Strategy: retry
Validate before calling
// before trusting a Done value
if let Err(StreamingError::IncompleteDoneValue) = validate_streaming_state(&value) {
// do not use the value; request continuation or retry
} Type guard
fn is_complete(value: &BamlValueWithFlags) -> bool {
validate_streaming_state(value).is_ok()
} Try / catch
match validate_streaming_state(&value) {
Err(StreamingError::IncompleteDoneValue) => retry_with_higher_budget().await?,
Err(e) => return Err(e.into()),
Ok(()) => commit(value),
} Prevention
- Set generous max_tokens budgets for structured output
- Avoid aggressive stop sequences that cut JSON mid-object
- Check proxy/client stream handling for truncation
- Retry transient truncations automatically
When it happens
Trigger: validate_streaming_state traverses nodes and finds one whose completion state is Done while its parsed value is still incomplete — e.g. the stream terminated mid-object after the parser optimistically marked it done, or truncated JSON that matched a done heuristic.
Common situations: LLM hit max_tokens mid-JSON; network/proxy cut the stream; stop-sequences fired early; parser heuristics marking partial braces as complete in very long outputs.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- Expected to encounter a class
- Class instance did not contain fields marked as needed: {fie
- Failed to distribute_type_with_meta: {0}
- Parsing failed due to: {s:?}
- Cannot stream expr function through this code path
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/686b8de17e9a39b2.
Report an issue: GitHub.