BoundaryML/baml · error

Internal error: no baml src reader provided

Error message

Internal error: no baml src reader provided

What it means

`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.

Solutions

  1. Construct the runtime with the baml source reader enabled (e.g. `with_baml_src(...)` / pass the source map when building `BamlRuntime`).
  2. Upgrade or align the BAML SDK version so runtime construction includes the src reader.
  3. Replace `baml://` media references with direct URLs (https://...) or base64 `baml-base64` media if no source dir is available.
  4. Report as a bug if the reader is set but still missing — this is labeled an internal error.

Example fix

// before
let rt = BamlRuntime::from_file_content(&dir, &files)?;

// after: ensure src reader is provided (available via context manager in most SDKs)
let ctx_manager = rt.create_ctx_manager(BamlValue::Null, None);
// and reference media through the project: baml://assets/my.pdf with the runtime's src root set
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure media references don't require baml:// when no src reader is configured
const usesBamlSrc = promptMedia.some(m => m.url.startsWith('baml://'));
if (usesBamlSrc && !runtimeHasBamlSrcReader()) {
  throw new Error('baml:// media used but runtime has no baml src reader');
}

Type guard

function canResolveBamlMedia(ctx) { return ctx && ctx.baml_src != null; }

Try / catch

try { await b.F(args); } catch (e) { if (String(e).includes('no baml src reader provided')) { initRuntimeWithSrcReader(); retry(); } }

Prevention

When it happens

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

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

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at engine/baml-runtime/src/internal/llm_client/traits/mod.rs:593

            let media_path = media_file.path()?.to_string_lossy().into_owned();

            if let Some(ext) = media_file.extension() {
                if render_settings.as_shell_commands {
                    return Ok(BamlMedia::base64(
                        part.media_type,
                        format!(
                            "$(base64 '{}')",
                            media_path
                                .strip_prefix("file://")
                                .unwrap_or(media_path.as_str())
                        ),
                        Some(format!("{}/{}", part.media_type, ext)),
                    ));
                }
            }

            let Some(ref baml_src_reader) = *ctx.baml_src else {
                anyhow::bail!("Internal error: no baml src reader provided");
            };

            let bytes = baml_src_reader(media_path.as_str())
                .await
                .context(format!("Failed to read file {media_path:#}"))?;

            let mut mime_type = part.mime_type.clone();

            if mime_type.is_none() {
                if let Some(ext) = media_file.extension() {
                    mime_type = Some(format!("{}/{}", part.media_type, ext));
                }
            }

            if mime_type.is_none() {
                if let Some(t) = infer::get(&bytes) {
                    mime_type = Some(t.mime_type().to_string());
                }

View on GitHub (pinned to bd85ce9dee)