{"record":{"id":"088f15af7aea593f","repo":"BoundaryML/baml","slug":"failing-inside-parsed-using-types-e","errorCode":null,"errorMessage":"failing inside parsed_using_types: {e:?}","messagePattern":"failing inside parsed_using_types: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/function_result.rs","lineNumber":49,"sourceCode":"    }\n\n    pub fn parsed_using_types(\n        ruby: &Ruby,\n        rb_self: &FunctionResult,\n        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","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/function_result.rs#L31-L67","documentation":"parsed_using_types converts a raw FunctionResult into typed Ruby objects using the provided types/partial_types TypeBuilders. When the internal parse (via the Rust core) fails, it wraps the debug-formatted error in a Ruby TypeError with this message.","triggerScenarios":"Calling function.parsed_using_types (or result.parsed_using_types) with TypeBuilders where the LLM output does not match the declared types, allow_partials mismatch, or malformed types passed in.","commonSituations":"LLM returns JSON not conforming to the output class, wrong type names in the TypeBuilder, or streaming partial parse hitting an incomplete object that cannot be validated.","solutions":["Print the embedded {e:?} detail — it names the actual validation failure","Verify the TypeBuilder classes/aliases match the prompt's output schema","Increase model reliability or improve the prompt's schema description","For streams, tolerate partials and wait for done before strict parsing"],"exampleFix":"// before\nparsed = result.parsed_using_types(types, partial_types, false)\n// after\nbegin\n  parsed = result.parsed_using_types(types, partial_types, false)\nrescue TypeError => e\n  warn \"Parse failed: #{e.message}\"\nend","handlingStrategy":"validation","validationCode":"# ensure declared types match expected output schema before parsing\ntypes.class_builder('Output').fields.each { |k, f| puts \"#{k}: #{f.r#type}\" }","typeGuard":null,"tryCatchPattern":"begin\n  parsed = result.parsed_using_types(types, partial_types, false)\nrescue TypeError => e\n  logger.error(\"schema mismatch: #{e.message}\")\nend","preventionTips":["Keep the prompt's output schema and TypeBuilder in sync","Test parsing against recorded LLM outputs","Use allow_partials=true only for streaming contexts"],"tags":["ruby","ffi","parsing","type-mismatch"],"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-14T05:17:10.506Z"}