BoundaryML/baml · error

Cannot stream expr function through this code path

Error message

Cannot stream expr function through this code path

What it means

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.

Source

Thrown at engine/baml-runtime/src/runtime_methods/stream_function.rs:97

                prepared_func: prepared.baml_args,
                ir: self.ir.clone(),
                orchestrator: vec![],
                tracer,
                renderer: PromptRenderer::mk_fake(),
                #[cfg(not(target_arch = "wasm32"))]
                tokio_runtime,
                collectors,
                tags: tags.cloned(),
                cancel_tripwire,
            })
        } else {
            let prepared = self
                .prepare_function(function_name, params)
                .map_err(|e| e.into_error())?;

            // let func = self.get_function(&function_name)?;
            let func = prepared.func.as_ref().ok_or_else(|| {
                anyhow::anyhow!("Cannot stream expr function through this code path")
            })?;
            let renderer = PromptRenderer::from_function(func, self.ir(), &ctx)?;
            let orchestrator = self.orchestration_graph(renderer.client_spec(), &ctx)?;
            Ok(FunctionResultStream {
                function_name: prepared.function_name,
                ir: self.ir.clone(),
                prepared_func: prepared.baml_args,
                orchestrator,
                tracer,
                renderer,
                #[cfg(not(target_arch = "wasm32"))]
                tokio_runtime,
                collectors,
                tags: tags.cloned(),
                cancel_tripwire,
            })
        }
    }

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Do not stream expr functions; call them and consume the complete result instead (use an expr-aware non-streaming path).
  2. If streaming is required, define the function as an LLM prompt function with a client in baml_src.
  3. Gate client code on the function kind so stream_function is only invoked for LLM functions.

Example fix

// before
let stream = runtime.stream_function("computed_value", params)?; // expr function
// after
let result = runtime.call_function("computed_value", params).await?; // non-streaming for expr fns
Defensive patterns

Strategy: try-catch

Validate before calling

// Client code: never stream expr functions
if is_expr_function(runtime, "my_fn") {
    let full = runtime.call_function("my_fn", params).await?; // consume complete result
}

Try / catch

// Rust
match runtime.stream_function("my_fn", params) {
    Err(e) if e.to_string().contains("Cannot stream expr") => {
        let r = runtime.call_function("my_fn", params).await?; // fallback
    }
    other => { /* handle stream */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/14c14f88062ba5e3. Report an issue: GitHub.