{"record":{"id":"969dba7152123c01","repo":"BoundaryML/baml","slug":"internal-error-no-baml-src-reader-provided","errorCode":null,"errorMessage":"Internal error: no baml src reader provided","messagePattern":"Internal error: no baml src reader provided","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/traits/mod.rs","lineNumber":593,"sourceCode":"            let media_path = media_file.path()?.to_string_lossy().into_owned();\n\n            if let Some(ext) = media_file.extension() {\n                if render_settings.as_shell_commands {\n                    return Ok(BamlMedia::base64(\n                        part.media_type,\n                        format!(\n                            \"$(base64 '{}')\",\n                            media_path\n                                .strip_prefix(\"file://\")\n                                .unwrap_or(media_path.as_str())\n                        ),\n                        Some(format!(\"{}/{}\", part.media_type, ext)),\n                    ));\n                }\n            }\n\n            let Some(ref baml_src_reader) = *ctx.baml_src else {\n                anyhow::bail!(\"Internal error: no baml src reader provided\");\n            };\n\n            let bytes = baml_src_reader(media_path.as_str())\n                .await\n                .context(format!(\"Failed to read file {media_path:#}\"))?;\n\n            let mut mime_type = part.mime_type.clone();\n\n            if mime_type.is_none() {\n                if let Some(ext) = media_file.extension() {\n                    mime_type = Some(format!(\"{}/{}\", part.media_type, ext));\n                }\n            }\n\n            if mime_type.is_none() {\n                if let Some(t) = infer::get(&bytes) {\n                    mime_type = Some(t.mime_type().to_string());\n                }","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/traits/mod.rs#L575-L611","documentation":"`process_media` resolves `baml://` media paths by reading from the BAML source directory via a reader installed in the runtime context. If `ctx.baml_src` is `None`, the runtime was constructed without a source reader, so BAML treats it as an internal invariant violation.","triggerScenarios":"Calling a BAML function whose prompt includes a `baml://` file reference (e.g. `baml://my.pdf`) with a runtime built without `with_baml_src`/file-reader set (common in WASM/embedding setups).","commonSituations":"Embedding BAML runtime in an app and forgetting to register the baml src reader, testing prompts with local-file media outside the CLI, or SDK versions where the runtime builder API changed and the reader hookup was dropped.","solutions":["Construct the runtime with the baml source reader enabled (e.g. `with_baml_src(...)` / pass the source map when building `BamlRuntime`).","Upgrade or align the BAML SDK version so runtime construction includes the src reader.","Replace `baml://` media references with direct URLs (https://...) or base64 `baml-base64` media if no source dir is available.","Report as a bug if the reader is set but still missing — this is labeled an internal error."],"exampleFix":"// before\nlet rt = BamlRuntime::from_file_content(&dir, &files)?;\n\n// after: ensure src reader is provided (available via context manager in most SDKs)\nlet ctx_manager = rt.create_ctx_manager(BamlValue::Null, None);\n// and reference media through the project: baml://assets/my.pdf with the runtime's src root set","handlingStrategy":"try-catch","validationCode":"// Ensure media references don't require baml:// when no src reader is configured\nconst usesBamlSrc = promptMedia.some(m => m.url.startsWith('baml://'));\nif (usesBamlSrc && !runtimeHasBamlSrcReader()) {\n  throw new Error('baml:// media used but runtime has no baml src reader');\n}","typeGuard":"function canResolveBamlMedia(ctx) { return ctx && ctx.baml_src != null; }","tryCatchPattern":"try { await b.F(args); } catch (e) { if (String(e).includes('no baml src reader provided')) { initRuntimeWithSrcReader(); retry(); } }","preventionTips":["Always construct BamlRuntime with the baml src reader in embedded/WASM contexts","Use absolute https:// URLs or base64 media when running outside the BAML project directory","Upgrade SDKs together so runtime-builder APIs stay consistent"],"tags":["baml","media","internal","configuration"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}