BoundaryML/baml · error · RuntimeError

error while building HTTP request for function {function_nam

Error message

error while building HTTP request for function {function_name}

What it means

Raised when the BAML runtime fails to render/build the HTTP request for a function via build_request. The anyhow context attaches the precise cause — prompt rendering failure, missing client or resolver mismatch, invalid client config — formatted with {:?} in the RuntimeError.

Source

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

                    format!("error while parsing call_function args:\n{e}"),
                ));
            }
        };

        rb_self
            .inner
            .build_request_sync(
                function_name.clone(),
                &args,
                &ctx.inner,
                type_registry.map(|t| &t.inner),
                client_registry.map(|c| c.inner.borrow_mut()).as_deref(),
                stream,
                env_vars,
            )
            .map(HTTPRequest::from)
            .map_err(|e| {
                Error::new(
                    ruby.exception_runtime_error(),
                    format!(
                        "{:?}",
                        e.context(format!(
                            "error while building HTTP request for function {function_name}"
                        ))
                    ),
                )
            })
    }

    pub fn parse_llm_response(
        ruby: &Ruby,
        rb_self: &BamlRuntimeFfi,
        function_name: String,
        llm_response: String,
        types: RModule,
        partial_types: RModule,

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read the {:?} detail for the exact rendering or client-resolution error.
  2. Verify the function's client is defined (or the client_registry passed contains it).
  3. Confirm all prompt-template parameters are supplied in args.
  4. Render-test the function in the BAML playground to validate the prompt compiles.

Example fix

// before
req = Baml.build_request('MyFn', args, ctx, ENV, false) # client 'gpt-4-turbo' not defined
// after
# define client "gpt-4-turbo" in .baml or pass a registry containing it
req = Baml.build_request('MyFn', args, ctx, ENV, false)
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, "client registry must be a Hash of Baml::Client strings" if client_registry && !client_registry.is_a?(Hash)

Try / catch

begin
  req = Baml.build_request(fn, args, ctx, ENV.to_h, stream)
rescue RuntimeError => e
  if e.message.include?('error while building HTTP request')
    logger.error("Request build failed for #{fn}: #{e.message}")
  end
  raise
end

Prevention

When it happens

Trigger: baml_runtime.build_request(...) returns Err: the function or its client cannot be resolved, prompt templates fail to render with the given args/ctx, or client_registry/client lookup fails.

Common situations: Referencing a named client that isn't defined in the .baml files; passing a client_registry that doesn't match; prompt template referencing parameters absent from args; dynamic client registry built incorrectly in Ruby.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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