{"record":{"id":"0749a156de037923","repo":"BoundaryML/baml","slug":"exposederror-formatted-via-format-last-error-with-details","errorCode":null,"errorMessage":"ExposedError (formatted via format_last_error_with_details)","messagePattern":"ExposedError \\(formatted via format_last_error_with_details\\)","errorType":"exception","errorClass":"ExposedError","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/types/response.rs","lineNumber":121,"sourceCode":"            Some((_, _, result)) => result,\n            None => &None,\n        }\n    }\n\n    pub fn result_with_constraints(&self) -> &Option<Result<ResponseBamlValue>> {\n        match self.event_chain.last() {\n            Some((_, _, result)) => result,\n            None => &None,\n        }\n    }\n\n    pub fn result_with_constraints_content(&self) -> Result<&ResponseBamlValue> {\n        let Some(result) = self\n            .result_with_constraints()\n            .as_ref()\n            .map(|res| match res {\n                Ok(val) => Ok(val),\n                Err(err) => Err(anyhow::anyhow!(self.format_last_error_with_details(err))),\n            })\n        else {\n            // If we don't have a parsed result, check if we have an LLMFailure\n            return match self.llm_response() {\n                    LLMResponse::LLMFailure(err) => {\n                        // Convert LLMFailure to appropriate error type\n                        match &err.code {\n                            crate::internal::llm_client::ErrorCode::Timeout => {\n                                Err(anyhow::anyhow!(crate::errors::ExposedError::TimeoutError {\n                                    client_name: err.client.clone(),\n                                    message: err.message.clone(),\n                                }))\n                            }\n                            crate::internal::llm_client::ErrorCode::Other(2) => {\n                                Err(anyhow::anyhow!(err.message.clone()))\n                            }\n                            _ => Err(anyhow::anyhow!(\n                                crate::errors::ExposedError::ClientHttpError {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/types/response.rs#L103-L139","documentation":"result_with_constraints_content re-wraps a stored error from the parsed result (result_with_constraints) using format_last_error_with_details, which renders the ExposedError with full diagnostic details. It surfaces whatever error the constrained parse produced, enriched with the last-attempt context.","triggerScenarios":"Calling .content()/result_with_constraints_content() on a ResponseChain whose result_with_constraints is Err — i.e. the LLM output failed constraint checks or parsing during the run.","commonSituations":"Schema parse failures (output didn't match the BAML return type), failed check()/assert() constraints in the prompt, or client-level errors recorded into the result slot.","solutions":["Inspect the detailed message from format_last_error_with_details to see the underlying parse/constraint failure.","Fix the prompt/schema so the model output matches the expected BAML type, or relax failing checks.","Catch this error at the call site and fall back to a retry with adjusted prompt or a different client."],"exampleFix":"// before\nlet value = chain.content().unwrap();\n\n// after\nmatch chain.result_with_constraints_content() {\n    Ok(v) => println!(\"{}\", v),\n    Err(e) => eprintln!(\"BAML detailed error: {e:#}\"),\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match chain.result_with_constraints_content() {\n    Ok(v) => handle(v),\n    Err(e) => log::error!(\"BAML detailed error: {e:#}\"),\n}","preventionTips":["Validate prompts so outputs match the BAML return schema","Test check()/assert() constraints against representative model outputs","Log {e:#} to preserve the full cause chain from format_last_error_with_details"],"tags":["rust","parsing","constraints"],"backgroundTag":"schema-validation-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}