{"record":{"id":"ad3d3996913e6fde","repo":"BoundaryML/baml","slug":"error-while-parsing-stream-function-args-e","errorCode":null,"errorMessage":"error while parsing stream_function args:\n{e}","messagePattern":"error while parsing stream_function args:\n(.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/lib.rs","lineNumber":174,"sourceCode":"\n        retval\n    }\n\n    fn stream_function(\n        ruby: &Ruby,\n        rb_self: &BamlRuntimeFfi,\n        function_name: String,\n        args: RHash,\n        ctx: &RuntimeContextManager,\n        type_registry: Option<&types::type_builder::TypeBuilder>,\n        client_registry: Option<&types::client_registry::ClientRegistry>,\n        collector: RArray,\n        env_vars: HashMap<String, String>,\n    ) -> Result<FunctionResultStream> {\n        let args = match ruby_to_json::RubyToJson::convert_hash_to_json(args) {\n            Ok(args) => args.into_iter().collect(),\n            Err(e) => {\n                return Err(Error::new(\n                    ruby.exception_syntax_error(),\n                    format!(\"error while parsing stream_function args:\\n{e}\"),\n                ));\n            }\n        };\n\n        let mut collectors = Vec::new();\n        for i in collector.into_iter() {\n            collectors.push(<&Collector>::try_convert(i)?.inner.clone());\n        }\n\n        log::debug!(\"Streaming {function_name} with:\\nargs: {args:#?}\\nctx ???\");\n\n        let retval = match rb_self.inner.stream_function(\n            function_name.clone(),\n            &args,\n            &ctx.inner,\n            type_registry.map(|t| &t.inner),","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs#L156-L192","documentation":"Raised inside stream_function when the Ruby kwargs hash cannot be converted to JSON for streaming function parameters. Same conversion path as call_function (RubyToJson), but raises a Ruby SyntaxError naming stream_function.","triggerScenarios":"Baml.stream_function(name, args, ...) with args containing non-JSON-serializable Ruby values (symbols, Date/Time, custom objects, IO handles).","commonSituations":"Streaming variant of arg serialization problems: passing raw Ruby objects for fields the prompt expects as strings; forgetting .to_json-compatible types in nested hashes.","solutions":["Inspect {e} to find the offending argument.","Convert all values to JSON-native Ruby types before the call.","Use string keys for nested hashes.","Serialize domain objects explicitly (iso8601 for dates, to_h for structs)."],"exampleFix":"// before\nBaml.stream_function('Chat', { created_at: Time.now }, ctx, ENV)\n// after\nBaml.stream_function('Chat', { 'created_at' => Time.now.utc.iso8601 }, ctx, ENV)","handlingStrategy":"validation","validationCode":"args.each { |k, v| raise TypeError, \"#{k} not JSON-serializable\" unless [String, Integer, Float, Hash, Array, NilClass, TrueClass, FalseClass].any? { |c| v.is_a?(c) } }","typeGuard":null,"tryCatchPattern":"begin\n  stream = Baml.stream_function(fn, args, ctx, ENV.to_h)\nrescue SyntaxError => e\n  raise unless e.message.include?('error while parsing stream_function args')\n  logger.error(\"Streaming args invalid for #{fn}: #{e.message}\") ; raise\nend","preventionTips":["Normalize args the same way as for call_function before streaming.","Convert symbols, dates, and custom objects to JSON-native values up front.","Share one serialization helper across call/stream/build_request paths.","Smoke-test args with JSON.generate in development."],"tags":["arguments","serialization","streaming","ruby"],"backgroundTag":"invalid-argument-format","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"}