{"record":{"id":"14c14f88062ba5e3","repo":"BoundaryML/baml","slug":"cannot-stream-expr-function-through-this-code-path","errorCode":null,"errorMessage":"Cannot stream expr function through this code path","messagePattern":"Cannot stream expr function through this code path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/runtime_methods/stream_function.rs","lineNumber":97,"sourceCode":"                prepared_func: prepared.baml_args,\n                ir: self.ir.clone(),\n                orchestrator: vec![],\n                tracer,\n                renderer: PromptRenderer::mk_fake(),\n                #[cfg(not(target_arch = \"wasm32\"))]\n                tokio_runtime,\n                collectors,\n                tags: tags.cloned(),\n                cancel_tripwire,\n            })\n        } else {\n            let prepared = self\n                .prepare_function(function_name, params)\n                .map_err(|e| e.into_error())?;\n\n            // let func = self.get_function(&function_name)?;\n            let func = prepared.func.as_ref().ok_or_else(|| {\n                anyhow::anyhow!(\"Cannot stream expr function through this code path\")\n            })?;\n            let renderer = PromptRenderer::from_function(func, self.ir(), &ctx)?;\n            let orchestrator = self.orchestration_graph(renderer.client_spec(), &ctx)?;\n            Ok(FunctionResultStream {\n                function_name: prepared.function_name,\n                ir: self.ir.clone(),\n                prepared_func: prepared.baml_args,\n                orchestrator,\n                tracer,\n                renderer,\n                #[cfg(not(target_arch = \"wasm32\"))]\n                tokio_runtime,\n                collectors,\n                tags: tags.cloned(),\n                cancel_tripwire,\n            })\n        }\n    }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/runtime_methods/stream_function.rs#L79-L115","documentation":"Streaming is not supported for BAML expression functions through `stream_function_impl`. Like call_function_impl, it needs a concrete LLM function (with prompt renderer and orchestrator); a prepared call whose `func` is None signals an expr function and is rejected with this error.","triggerScenarios":"Calling `stream_function` (or run_test_with_expr_events / stream_function_with_expr_events reaching this path) on a function defined as an expression function in BAML rather than an LLM prompt function.","commonSituations":"Adding streaming to client code that later points at an expr function; converting a prompt function to an expr function while callers still use stream_function; test runners streaming an expr-based function.","solutions":["Do not stream expr functions; call them and consume the complete result instead (use an expr-aware non-streaming path).","If streaming is required, define the function as an LLM prompt function with a client in baml_src.","Gate client code on the function kind so stream_function is only invoked for LLM functions."],"exampleFix":"// before\nlet stream = runtime.stream_function(\"computed_value\", params)?; // expr function\n// after\nlet result = runtime.call_function(\"computed_value\", params).await?; // non-streaming for expr fns","handlingStrategy":"try-catch","validationCode":"// Client code: never stream expr functions\nif is_expr_function(runtime, \"my_fn\") {\n    let full = runtime.call_function(\"my_fn\", params).await?; // consume complete result\n}","typeGuard":null,"tryCatchPattern":"// Rust\nmatch runtime.stream_function(\"my_fn\", params) {\n    Err(e) if e.to_string().contains(\"Cannot stream expr\") => {\n        let r = runtime.call_function(\"my_fn\", params).await?; // fallback\n    }\n    other => { /* handle stream */ }\n}","preventionTips":["Maintain a list of expr functions in your client and exclude them from streaming paths.","When converting a prompt function to an expr function, audit all stream_function call sites.","Prefer non-streaming consumption for expr/computed functions."],"tags":["rust","unsupported-operation","streaming","expr-function"],"backgroundTag":"unsupported-operation","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"}