BoundaryML/baml · error · JsonishError
No collection to consume token: {0:?}
Error message
No collection to consume token: {0:?} What it means
`JsonishError::NoCollectionForToken(char)` is raised when the tokenizer/consumer encounters a collection-opening token (an object or array delimiter) while no collection is currently open on the parse stack — the input has a stray closing delimiter or an orphaned token with nothing to attach to. The `char` payload identifies the offending token.
Source
Thrown at baml_language/crates/bex_sap/src/jsonish/mod.rs:23
mod parser;
mod value;
pub use parser::{ParseOptions, parse};
pub use value::{CompletionState, Fixes, Value};
/// Error type for jsonish parsing failures.
#[derive(Debug, thiserror::Error)]
pub enum JsonishError {
#[error("Depth limit reached. Likely a circular reference.")]
DepthLimitReached,
#[error("No JSON objects found")]
NoJsonObjectsFound,
#[error("No markdown blocks found")]
NoMarkdownBlocksFound,
#[error("Mismatched brackets")]
MismatchedBrackets,
#[error("No collection to consume token: {0:?}")]
NoCollectionForToken(char),
#[error("Failed to parse JSON")]
ParseFailed,
}
View on GitHub (pinned to bd85ce9dee)
Solutions
- Examine the reported character's position in the input and remove the stray delimiter or restore the missing opening one.
- Improve pre-extraction so it slices complete JSON objects, not fragments.
- Ask the model for a single complete JSON value with no surrounding code samples.
- Add a validation/sanitizing step before parsing to drop obviously incomplete fragments.
Example fix
// before let v = jsonish::parse(frag, &opts)?; // frag: "...} ]" // after let frag = extract_first_complete_object(&raw).ok_or(MyErr::NoJson)?; let v = jsonish::parse(&frag, &opts)?;
Defensive patterns
Strategy: validation
Validate before calling
fn has_orphan_closers(s: &str) -> bool {
let mut d = 0i32;
for c in s.chars() {
match c { '{' | '[' => d += 1, '}' | ']' => { d -= 1; if d < 0 { return true } }, _ => {} }
}
false
}
// if has_orphan_closers(raw), fix extraction boundaries first Try / catch
match jsonish::parse(&frag, &opts) {
Ok(v) => Ok(v),
Err(JsonishError::NoCollectionForToken(c)) => Err(format!("stray '{c}' — fix extraction slice")),
Err(e) => Err(e.into()),
} Prevention
- Slice complete JSON objects, not fragments, during pre-extraction.
- Exclude code samples from candidate extraction ranges.
- Run a delimiter-balance check before parsing.
When it happens
Trigger: Calling `bex_sap::jsonish::parse` on text with stray `}`, `]`, or similar delimiters outside any open `{`/`[` — e.g. fragments of JSON mixed into prose.
Common situations: The model emits partial JSON fragments or code samples containing braces; a regex-based pre-extraction step cut the JSON in the wrong place leaving orphaned delimiters.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- Mismatched brackets
- Mismatched brackets
- Depth limit reached. Likely a circular reference.
- No JSON objects found
- Failed to parse JSON
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/42626e11bfeb5ccb.
Report an issue: GitHub.