{"record":{"id":"8c5c3a96c912a5f7","repo":"BoundaryML/baml","slug":"parsing-failed-due-to-s","errorCode":null,"errorMessage":"Parsing failed due to: {s:?}","messagePattern":"Parsing failed due to: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jsonish/src/helpers/mod.rs","lineNumber":345,"sourceCode":"        baml_value.clone().into();\n    let meta_field_type: BamlValueWithMeta<TypeIR> = baml_value.clone().into();\n\n    let value_with_response_checks: BamlValueWithMeta<Vec<ResponseCheck>> = baml_value_with_meta\n        .map_meta(|cs| {\n            cs.iter()\n                .map(|(label, expr, result)| {\n                    let status = (if *result { \"succeeded\" } else { \"failed\" }).to_string();\n                    ResponseCheck {\n                        name: label.clone(),\n                        expression: expr.0.clone(),\n                        status,\n                    }\n                })\n                .collect()\n        });\n\n    let baml_value_with_streaming = validate_streaming_state(ir, &baml_value, mode)\n        .map_err(|s| anyhow::anyhow!(\"Parsing failed due to: {s:?}\"))?;\n\n    // Combine the baml_value, its types, the parser flags, and the streaming state\n    // into a final value.\n    // Node that we set the StreamState to `None` unless `allow_partials`.\n    let response_value = baml_value_with_streaming\n        .zip_meta(&value_with_response_checks)?\n        .zip_meta(&meta_flags)?\n        .zip_meta(&meta_field_type)?\n        .map_meta(|(((x, y), z), ft)| {\n            crate::ResponseValueMeta(z.clone(), y.clone(), x.clone(), ft.clone())\n        });\n    Ok(ResponseBamlValue(response_value))\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jsonish/src/helpers/mod.rs#L327-L363","documentation":"In parsed_value_to_response, the jsonish parser validates streaming/partial-parse state via validate_streaming_state; if that check reports a problem, the error string is wrapped with anyhow as 'Parsing failed due to: {s:?}'. It means the LLM output parsed as JSON-ish but its streaming state (partial vs complete values, allow_partials mode) is inconsistent with what the caller requested.","triggerScenarios":"Calling BAML response parsing (from_str -> parsed_value_to_response) with a stream that is not done while allow_partials is not enabled, or with a partial value that cannot be validated as a valid streaming state for the requested mode.","commonSituations":"Consuming intermediate streaming chunks from an LLM without setting allow_partials, or feeding truncated tool-call/JSON output into the final (non-streaming) parse path.","solutions":["Read the inner '{s:?}' detail in the message to identify the underlying validation failure","If parsing partial stream chunks, enable allow_partials in the parse options","Only call the final parse once the stream is complete (is_done=true)","Log/inspect the raw LLM text; malformed streaming output may need a retry of the generation"],"exampleFix":"// before\nlet value = jsonish::from_str(&target_type, raw_chunk)?;\n// after\nlet value = jsonish::from_str_with_flags(&target_type, raw_chunk, ParseOptions { allow_partials: true, ..Default::default() })?;","handlingStrategy":"try-catch","validationCode":"fn can_parse(s: &str, allow_partials: bool) -> bool { !s.trim().is_empty() && (allow_partials || looks_complete(s)) }","typeGuard":"fn looks_complete(s: &str) -> bool { s.trim_end().ends_with('}') || s.trim_end().ends_with(']') }","tryCatchPattern":"match jsonish::from_str(&t, chunk) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"Parsing failed due to\") => fallback_partial(),\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Enable allow_partials when consuming streaming chunks","Only finalize parse on stream completion","Log the raw chunk on every parse failure"],"tags":["json","streaming","parsing","rust"],"backgroundTag":"invalid-json-response","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}