{"record":{"id":"d8f95f3ab3f3a26c","repo":"BoundaryML/baml","slug":"failed-to-stream-function","errorCode":null,"errorMessage":"Failed to stream function: {}","messagePattern":"Failed to stream function: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_cffi/src/ffi/functions.rs","lineNumber":294,"sourceCode":"    let ctx = runtime.create_ctx_manager(BamlValue::String(\"cffi\".to_string()), None);\n    // TODO: There's a race condition bug here. Technically we should COPY the type builder, not just clone it.\n    let type_builder = type_builder.map(|t| t.type_builder.as_ref().clone());\n    let client_registry_clone = client_registry.clone();\n    let env_vars_clone = env_vars.clone();\n    let mut stream = match runtime.stream_function(\n        func_name,\n        &kwargs,\n        &ctx,\n        type_builder.as_ref(),\n        client_registry.as_ref(),\n        collectors.map(|c| c.iter().map(|c| c.deref().clone()).collect()),\n        env_vars,\n        tripwire,\n        Some(&tags),\n    ) {\n        Ok(stream) => stream,\n        Err(e) => {\n            return Err(anyhow::anyhow!(\"Failed to stream function: {}\", e));\n        }\n    };\n\n    let ctx = runtime.create_ctx_manager(BamlValue::String(\"cffi\".to_string()), None);\n\n    RUNTIME.spawn(async move {\n        // Create the stream.run future\n        let (final_result, _) = stream\n            .run(\n                Some(|| on_tick(id)),\n                Some(|r| on_event(id, r, runtime)),\n                &ctx,\n                type_builder.as_ref(),\n                client_registry_clone.as_ref(),\n                env_vars_clone,\n            )\n            .await;\n","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_cffi/src/ffi/functions.rs#L276-L312","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the embedded cause after \"Failed to stream function: \" and fix that root cause first","Verify the function exists in your .baml files and regenerate the client if it changed","Check that required env vars / API keys for the LLM provider are set","Ensure argument names and types match the BAML function signature"],"exampleFix":"// before\nstream = client.stream(\"ExtratResume\", {text: t})  # typo'd function\n// after\nstream = client.stream(\"ExtractResume\", {text: t})  # matches .baml definition","handlingStrategy":"try-catch","validationCode":"assert func_name in baml_functions_in_baml_files(), f\"{func_name} not defined in .baml\"\nfor k in required_params(func_name): assert k in kwargs","typeGuard":null,"tryCatchPattern":"try:\n    stream = client.stream(func_name, kwargs)\nexcept Exception as e:\n    if 'Failed to stream function' in str(e):\n        log.error('stream start failed', cause=str(e))  # inspect embedded cause\n        raise RuntimeError(f\"Cannot stream {func_name}: {e}\") from e\n    raise","preventionTips":["Regenerate clients after renaming/editing .baml functions","Ensure LLM provider API keys/env vars are set before streaming","Match argument names/types to the BAML function signature","Pin compatible client and native runtime versions"],"tags":["ffi","rust","streaming","runtime"],"backgroundTag":"api-request-failed","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"}