{"record":{"id":"722e220be3f61200","repo":"BoundaryML/baml","slug":"llm-call-failed-failure","errorCode":null,"errorMessage":"LLM call failed: {failure:?}","messagePattern":"LLM call failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/mod.rs","lineNumber":200,"sourceCode":"impl std::fmt::Display for LLMResponse {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        match self {\n            Self::Success(response) => write!(f, \"{response}\"),\n            Self::LLMFailure(failure) => write!(f, \"LLM call failed: {failure:?}\"),\n            Self::UserFailure(message) => {\n                write!(f, \"Failed before LLM call (user error): {message}\")\n            }\n            Self::InternalFailure(message) => write!(f, \"Failed before LLM call: {message}\"),\n            Self::Cancelled(message) => write!(f, \"Operation cancelled: {message}\"),\n        }\n    }\n}\n\nimpl LLMResponse {\n    pub fn content(&self) -> Result<&str> {\n        match self {\n            Self::Success(response) => Ok(&response.content),\n            Self::LLMFailure(failure) => Err(anyhow::anyhow!(\"LLM call failed: {failure:?}\")),\n            Self::UserFailure(message) => Err(anyhow::anyhow!(\n                \"Failed before LLM call (user error): {message}\"\n            )),\n            Self::InternalFailure(message) => {\n                Err(anyhow::anyhow!(\"Failed before LLM call: {message}\"))\n            }\n            Self::Cancelled(message) => Err(anyhow::anyhow!(\"Operation cancelled: {message}\")),\n        }\n    }\n}\n\n#[derive(Debug, Clone, Serialize, PartialEq)]\npub struct LLMErrorResponse {\n    pub client: String,\n    pub model: Option<String>,\n    pub prompt: RenderedPrompt,\n    pub request_options: BamlMap<String, serde_json::Value>,\n    #[cfg_attr(target_arch = \"wasm32\", serde(skip_serializing))]","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/mod.rs#L182-L218","documentation":"LLMResponse::content() extracts the text of a successful LLM response; if the runtime's result is an LLMFailure variant (the LLM call itself ran and failed — e.g. HTTP error, provider refusal, timeout), content() converts it into an anyhow error embedding the full debug dump of the LLMFailure struct. This error surfaces provider-side call failures to callers that only want the text content.","triggerScenarios":"Calling .content() (or code paths that unwrap content) on an LLMResponse that is LLMFailure — i.e. the provider returned an error status, invalid response, or the request failed after retries.","commonSituations":"Invalid API key leading to 401 from the provider; model name not available to the account; rate limits or provider outages; malformed requests rejected by the provider.","solutions":["Inspect the embedded failure debug dump in the message for the provider's status/error body","Match on the LLMResponse variant before calling content() and handle LLMFailure explicitly","Check provider credentials (API keys) and model availability","Add/review a retry policy in the BAML client config for transient provider failures"],"exampleFix":"// before\nlet text = response.content()?;\n// after\nlet text = match response {\n    LLMResponse::Success(r) => &r.content,\n    LLMResponse::LLMFailure(f) => return Err(handle_llm_failure(f)), // inspect f.message/status\n    other => return Err(anyhow::anyhow!(\"unexpected response: {other:?}\")),\n};","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn llm_content(r: &LLMResponse) -> Option<&str> {\n    match r { LLMResponse::Success(resp) => Some(&resp.content), _ => None }\n}","tryCatchPattern":"match llm_response {\n    LLMResponse::Success(r) => Ok(&r.content),\n    LLMResponse::LLMFailure(f) => Err(map_provider_failure(f)), // check status/body, maybe retry\n    other => Err(anyhow::anyhow!(\"not an LLM response: {other:?}\")),\n}","preventionTips":["Configure a retry policy for transient provider errors (429/5xx)","Validate API keys and model names before deployment","Always match on LLMResponse variants instead of unwrapping content()","Log the failure debug dump to diagnose provider-side causes"],"tags":["baml","llm-provider","request-failed","error-handling"],"backgroundTag":"upstream-api-error","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"}