{"record":{"id":"acbea0f8d4438005","repo":"BoundaryML/baml","slug":"parse-response-error-0","errorCode":null,"errorMessage":"Parse response error: {0}","messagePattern":"Parse response error: (.+?)","errorType":"exception","errorClass":"LlmOpError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/sys_ops/src/sap.rs","lineNumber":58,"sourceCode":"        >,\n        &DefKey,\n    > {\n        self.db().resolve_with_meta(self.types.stream_ty().as_ref())\n    }\n}\n\n/// Errors that can occur during LLM operations. Relocated verbatim from\n/// `sys_llm`; only `ParseResponseError`, `JsonishError` and `SapError` are\n/// still constructible now that the SAP parse entry points are the sole users.\n#[derive(Debug, thiserror::Error)]\npub enum LlmOpError {\n    #[error(\"Expected {expected}, got {actual}\")]\n    TypeError {\n        expected: &'static str,\n        actual: String,\n    },\n\n    #[error(\"Parse response error: {0}\")]\n    ParseResponseError(String),\n\n    #[error(\"Jsonish error: {0}\")]\n    JsonishError(::bex_sap::jsonish::JsonishError),\n\n    #[error(\"SAP error: {0}\")]\n    SapError(::bex_sap::deserializer::coercer::ParsingError),\n}\n\nimpl From<LlmOpError> for ::sys_types::VmRustFnError {\n    fn from(e: LlmOpError) -> Self {\n        let baml: ::sys_types::VmBamlError = match e {\n            LlmOpError::TypeError { expected, actual } => {\n                ::sys_types::VmBamlError::InvalidArgument {\n                    message: format!(\"expected {expected}, got {actual}\"),\n                }\n            }\n            LlmOpError::ParseResponseError(e) => ::sys_types::VmBamlError::LlmClient { message: e },","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/sys_ops/src/sap.rs#L40-L76","documentation":"Generic wrapper in LlmOpError for failures while parsing an LLM provider's response body into the expected structure (the {0} inner message carries the specifics from the underlying parser). It fires in the SAP parse entry points when response text cannot be converted to the declared output type — malformed JSON, unexpected shape, or converter failure.","triggerScenarios":"The SAP response-parsing entry point fails to interpret the raw LLM output (non-JSON text, truncated output, unexpected structure) and returns ParseResponseError with a descriptive message.","commonSituations":"Model returns prose instead of JSON; response cut off by token limits; prompt asks for a format the parser doesn't support.","solutions":["Strengthen the prompt/output-format instructions so the model returns parseable output","Enable or rely on jsonish repair/coercion for slightly malformed responses","Check the raw response for truncation and increase max tokens if needed"],"exampleFix":"// before\nraw_response.parse()\n// after\nparse_with_repair(raw_response).map_err(|e| ParseResponseError(e.to_string()))","handlingStrategy":"retry","validationCode":"if !raw.trim_start().starts_with('{') && !raw.trim_start().starts_with('[') {\n    // not parseable output; retry or repair before calling the parser\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(LlmOpError::ParseResponseError(msg)) => { log::warn!(\"parse failed: {msg}\"); retry_with_stricter_prompt() }\n    other => other,\n}","preventionTips":["Use structured-output/JSON mode when the provider supports it","Check for truncation and raise max tokens","Retry once on parse failure — LLM formatting faults are often transient"],"tags":["llm","parsing","response"],"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-14T05:17:10.506Z"}