BoundaryML/baml · error

baml.fetch_as expects 1 argument (url), got {} at {:?}

Error message

baml.fetch_as expects 1 argument (url), got {} at {:?}

What it means

Thrown when the `baml.fetch_as` builtin is called without exactly one argument. The builtin fetches the content at a URL and interprets it as the type given by its single type argument, so it requires exactly one runtime argument (the url).

Source

Thrown at engine/baml-compiler/src/thir/interpret.rs:2736

                    args.len(),
                    meta.0
                );
            }
            let url = match &args[0] {
                BamlValueWithMeta::String(s, _) => s.clone(),
                _ => bail!(
                    "baml.media.image.from_url expects a string argument at {:?}",
                    meta.0
                ),
            };
            Ok(BamlValueWithMeta::Media(
                baml_types::BamlMedia::url(baml_types::BamlMediaType::Image, url, None),
                meta.clone(),
            ))
        }
        "baml.fetch_as" => {
            if args.len() != 1 {
                bail!(
                    "baml.fetch_as expects 1 argument (url), got {} at {:?}",
                    args.len(),
                    meta.0
                );
            }
            if type_args.len() != 1 {
                bail!(
                    "baml.fetch_as expects 1 type argument, got {} at {:?}",
                    type_args.len(),
                    meta.0
                );
            }

            let url = match &args[0] {
                BamlValueWithMeta::String(s, _) => s.clone(),
                _ => bail!(
                    "baml.fetch_as expects a string URL argument at {:?}",
                    meta.0

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Call baml.fetch_as with exactly one argument: the URL string
  2. Remove extra positional options; the builtin only accepts the url
  3. If configuration is needed, set it outside the call or via supported mechanisms, not extra arguments
  4. Check dynamically-built argument lists (spreads) so only one value is passed

Example fix

// before (BAML)
let data = baml.fetch_as<MyType>(url, 30);
// after
let data = baml.fetch_as<MyType>(url);
Defensive patterns

Strategy: validation

Validate before calling

function validateFetchAsArgs(args: unknown[]): void {
  if (args.length !== 1) {
    throw new Error(`baml.fetch_as expects 1 argument (url), got ${args.length}`);
  }
  if (typeof args[0] !== 'string') {
    throw new Error('baml.fetch_as url must be a string');
  }
}

Try / catch

try {
  data = evaluate(call);
} catch (e) {
  if (String(e).includes('baml.fetch_as expects 1 argument')) {
    // drop extra positional options from the call
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling baml.fetch_as<T>() with 0 arguments, or 2+ arguments (e.g. url plus options/headers), which the current builtin signature does not support.

Common situations: Passing extra fetch options positionally (timeout, headers) out of habit from other HTTP libraries, or forgetting the url argument when the type parameter is supplied but the value omitted.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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