BoundaryML/baml · error

Failed to stream function: {}

Error message

Failed to stream function: {}

What it means

This error wraps the underlying BamlRuntime failure when the runtime cannot start streaming a function — e.g. the function name is not found, parameters fail validation, or context/LLM client setup fails. The original error is embedded in the message after the prefix.

Source

Thrown at engine/language_client_cffi/src/ffi/functions.rs:294

    let ctx = runtime.create_ctx_manager(BamlValue::String("cffi".to_string()), None);
    // TODO: There's a race condition bug here. Technically we should COPY the type builder, not just clone it.
    let type_builder = type_builder.map(|t| t.type_builder.as_ref().clone());
    let client_registry_clone = client_registry.clone();
    let env_vars_clone = env_vars.clone();
    let mut stream = match runtime.stream_function(
        func_name,
        &kwargs,
        &ctx,
        type_builder.as_ref(),
        client_registry.as_ref(),
        collectors.map(|c| c.iter().map(|c| c.deref().clone()).collect()),
        env_vars,
        tripwire,
        Some(&tags),
    ) {
        Ok(stream) => stream,
        Err(e) => {
            return Err(anyhow::anyhow!("Failed to stream function: {}", e));
        }
    };

    let ctx = runtime.create_ctx_manager(BamlValue::String("cffi".to_string()), None);

    RUNTIME.spawn(async move {
        // Create the stream.run future
        let (final_result, _) = stream
            .run(
                Some(|| on_tick(id)),
                Some(|r| on_event(id, r, runtime)),
                &ctx,
                type_builder.as_ref(),
                client_registry_clone.as_ref(),
                env_vars_clone,
            )
            .await;

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the embedded cause after "Failed to stream function: " and fix that root cause first
  2. Verify the function exists in your .baml files and regenerate the client if it changed
  3. Check that required env vars / API keys for the LLM provider are set
  4. Ensure argument names and types match the BAML function signature

Example fix

// before
stream = client.stream("ExtratResume", {text: t})  # typo'd function
// after
stream = client.stream("ExtractResume", {text: t})  # matches .baml definition
Defensive patterns

Strategy: try-catch

Validate before calling

assert func_name in baml_functions_in_baml_files(), f"{func_name} not defined in .baml"
for k in required_params(func_name): assert k in kwargs

Try / catch

try:
    stream = client.stream(func_name, kwargs)
except Exception as e:
    if 'Failed to stream function' in str(e):
        log.error('stream start failed', cause=str(e))  # inspect embedded cause
        raise RuntimeError(f"Cannot stream {func_name}: {e}") from e
    raise

Prevention

When it happens

Trigger: Calling baml_call_function_stream with a function name not present in the loaded .baml files, wrong argument names/types, or a runtime environment (env vars, client registry, tags) that fails runtime.stream_function.

Common situations: Function renamed or removed from .baml files without regenerating clients, missing LLM provider API keys in env vars, stale compiled BAML assets not matching the runtime version, or invalid parameter values rejected at stream start.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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