BoundaryML/baml · error · RuntimeError

error while calling

Error message

error while calling {function_name}

What it means

Raised when the BAML runtime itself fails while executing a function invoked via call_function. The specific underlying failure (client config, prompt rendering, provider error, parsing) is attached via anyhow context and printed with {:?} after the message.

Solutions

  1. Read the {:?} detail for the exact underlying cause.
  2. Verify the function name exists in your .baml files (or reload the runtime after edits).
  3. Check required API keys are present in the env_vars passed to the runtime/call.
  4. Test the function in the BAML playground / CLI to reproduce outside Ruby.
  5. Wrap the call in begin/rescue and inspect the message to distinguish config vs provider errors.

Example fix

// before
res = Baml.call_function('ExtractResume', args, ctx, {}) # missing API key env
// after
res = Baml.call_function('ExtractResume', args, ctx, ENV.to_h.merge('OPENAI_API_KEY' => api_key))
Defensive patterns

Strategy: try-catch

Validate before calling

raise ArgumentError, "function '#{fn}' not found" unless File.read(baml_files.join).scan(/function\s+#{fn}\b/).any?

Try / catch

begin
  res = Baml.call_function(fn, args, ctx, ENV.to_h)
rescue RuntimeError => e
  logger.error("BAML call_function failed for #{fn}: #{e.message}")
  raise
end

Prevention

When it happens

Trigger: baml_runtime.call_function(...) returns Err for any reason: unknown function name, misconfigured LLM client, missing API key in env_vars, provider HTTP failure, or output-parsing failure.

Common situations: Calling a function name that doesn't exist in the .baml files; missing OPENAI_API_KEY/ANTHROPIC_API_KEY; wrong model name in client config; network failures or provider rate limits.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at engine/language_client_ruby/ext/ruby_ffi/src/lib.rs:148

        let mut collectors = Vec::new();
        for i in collector.into_iter() {
            collectors.push(<&Collector>::try_convert(i)?.inner.clone());
        }

        let retval = match rb_self.t.block_on(rb_self.inner.call_function(
            function_name.clone(),
            &args,
            &ctx.inner,
            type_registry.map(|t| &t.inner),
            client_registry.map(|c| c.inner.borrow_mut()).as_deref(),
            Some(collectors),
            env_vars,
            None,
            TripWire::new(None),
        )) {
            (Ok(res), _) => Ok(FunctionResult::new(res)),
            (Err(e), _) => Err(Error::new(
                ruby.exception_runtime_error(),
                format!(
                    "{:?}",
                    e.context(format!("error while calling {function_name}"))
                ),
            )),
        };

        retval
    }

    fn stream_function(
        ruby: &Ruby,
        rb_self: &BamlRuntimeFfi,
        function_name: String,
        args: RHash,
        ctx: &RuntimeContextManager,
        type_registry: Option<&types::type_builder::TypeBuilder>,

View on GitHub (pinned to bd85ce9dee)