{"record":{"id":"4a2e44b0524d6198","repo":"BoundaryML/baml","slug":"failed-to-initialize-baml-runtime","errorCode":null,"errorMessage":"Failed to initialize BAML runtime","messagePattern":"Failed to initialize BAML runtime","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/lib.rs","lineNumber":61,"sourceCode":"            .build()\n            .map_err(|e| {\n                Error::new(\n                    ruby.exception_runtime_error(),\n                    format!(\"Failed to start tokio runtime because:\\n{e:?}\"),\n                )\n            })\n    }\n\n    pub fn from_directory(\n        ruby: &Ruby,\n        directory: PathBuf,\n        env_vars: HashMap<String, String>,\n    ) -> Result<BamlRuntimeFfi> {\n        let baml_runtime =\n            match BamlRuntime::from_directory(&directory, env_vars, FeatureFlags::new()) {\n                Ok(br) => br,\n                Err(e) => {\n                    return Err(Error::new(\n                        ruby.exception_runtime_error(),\n                        format!(\"{:?}\", e.context(\"Failed to initialize BAML runtime\")),\n                    ))\n                }\n            };\n\n        let rt = BamlRuntimeFfi {\n            inner: Arc::new(baml_runtime),\n            t: Arc::new(Self::make_tokio_runtime(ruby)?),\n        };\n\n        Ok(rt)\n    }\n\n    pub fn from_files(\n        ruby: &Ruby,\n        root_path: String,\n        files: HashMap<String, String>,","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs#L43-L79","documentation":"Raised when Baml::Runtime.from_directory cannot construct the BAML runtime from the given directory containing .baml files. The underlying cause is formatted into the RuntimeError via anyhow's context, so the real validation/compiler error follows the message text.","triggerScenarios":"Baml::Runtime.from_directory(directory, env_vars) is called with a directory path that doesn't exist, has no valid .baml files, or whose BAML sources fail to compile (syntax errors, invalid config, bad client definitions).","commonSituations":"Pointing from_directory at the wrong project root (baml_src missing); renaming or deleting .baml files; BAML syntax errors after edits; stale references to removed BAML functions/clients.","solutions":["Read the {:?} output after the message — it contains the specific compiler/IO error.","Verify the directory is the BAML source directory (contains .baml files, e.g. baml_src/).","Run `baml-cli dev` or the BAML CLI on the same directory to surface syntax/config errors quickly.","Fix any reported .baml syntax or client configuration errors, then retry."],"exampleFix":"// before\nBaml::Runtime.from_directory('./src', ENV.to_h)   # wrong dir, no .baml files\n// after\nBaml::Runtime.from_directory('./baml_src', ENV.to_h) # directory with valid .baml files","handlingStrategy":"validation","validationCode":"dir = './baml_src'\nraise ArgumentError, \"#{dir} is not a directory\" unless Dir.exist?(dir)\nraise ArgumentError, \"no .baml files in #{dir}\" if Dir.glob(File.join(dir, '**/*.baml')).empty?","typeGuard":null,"tryCatchPattern":"begin\n  runtime = Baml::Runtime.from_directory(dir, ENV.to_h)\nrescue RuntimeError => e\n  logger.error(\"BAML init failed: #{e.message}\")\n  raise\nend","preventionTips":["Point from_directory at the directory that actually contains .baml files.","Compile-check .baml sources with the BAML CLI in CI before runtime load.","Reload the runtime after any .baml edit.","Include env vars needed by client definitions at init time."],"tags":["initialization","configuration","baml","ruby"],"backgroundTag":"config-file-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}