{"record":{"id":"2982c8f9ddc6826e","repo":"BoundaryML/baml","slug":"failed-to-parse-llm-response","errorCode":null,"errorMessage":"Failed to parse LLM response: {}","messagePattern":"Failed to parse LLM response: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/function_result.rs","lineNumber":54,"sourceCode":"        types: RModule,\n        partial_types: RModule,\n        allow_partials: bool,\n    ) -> Result<Value> {\n        let res = match rb_self.inner.result_with_constraints_content() {\n            Ok(parsed) => ruby_to_json::RubyToJson::serialize_baml(\n                ruby,\n                types,\n                partial_types,\n                allow_partials,\n                parsed.clone(),\n            )\n            .map_err(|e| {\n                magnus::Error::new(\n                    ruby.exception_type_error(),\n                    format!(\"failing inside parsed_using_types: {e:?}\"),\n                )\n            }),\n            Err(_) => Err(Error::new(\n                ruby.exception_runtime_error(),\n                format!(\"Failed to parse LLM response: {}\", rb_self.inner),\n            )),\n        };\n        res\n    }\n\n    /// For usage in magnus::init\n    ///\n    /// TODO: use traits and macros to implement this\n    pub fn define_in_ruby(module: &RModule) -> Result<()> {\n        let cls = module.define_class(\"FunctionResult\", class::object())?;\n\n        cls.define_method(\n            \"parsed_using_types\",\n            method!(FunctionResult::parsed_using_types, 3),\n        )?;\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/function_result.rs#L36-L72","documentation":"The sibling branch of parsed_using_types: when the inner FunctionResult itself has no content (the LLM call failed), the FFI raises a Ruby RuntimeError 'Failed to parse LLM response: <result>'. Unlike the TypeError branch, this indicates no response existed to parse.","triggerScenarios":"Calling parsed_using_types on a FunctionResult whose content() is Err — failed/aborted LLM call, empty response — rather than a schema mismatch.","commonSituations":"Provider errors, rate limits, or timeouts that return a result object with no payload, then attempting typed parsing without checking success first.","solutions":["Check the result succeeded before parsing (inspect content/status)","Handle the RuntimeError and surface the underlying provider error","Configure retries/fallbacks in the BAML function's client strategy","Validate API keys and provider health"],"exampleFix":"// before\nparsed = result.parsed_using_types(types, partial_types, false)\n// after\nparsed =\n  begin\n    result.parsed_using_types(types, partial_types, false)\n  rescue RuntimeError => e\n    warn \"No LLM response to parse: #{e.message}\"\n    nil\n  end","handlingStrategy":"try-catch","validationCode":"# only parse when the call succeeded\nnext unless result && result.content # or equivalent success check","typeGuard":null,"tryCatchPattern":"begin\n  parsed = result.parsed_using_types(types, partial_types, false)\nrescue RuntimeError => e\n  logger.error(\"no LLM response: #{e.message}\")\n  parsed = nil\nend","preventionTips":["Check for successful completion before typed parsing","Add retries/fallbacks to the function's client","Alert on provider failures before parsing stage"],"tags":["ruby","ffi","llm-response","parsing"],"backgroundTag":"empty-response-body","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"}