Skip to main content

Signature

Overview

Unlike Anthropic, OpenAI, LangChain, and Gemini — which are auto-instrumented automatically — BAML clients are code-generated per project and cannot be monkey-patched. You must explicitly wrap the client with instrument_baml().
If you use BAML without calling instrument_baml(), calls will not be traced. There is no error — they simply won’t appear in traces.

Parameters

Any
required
The BAML client instance to wrap. Typically imported as b from baml_client.

Returns

A proxy-wrapped client with tracing enabled. Assign the result back to your client variable.

Example

How It Works

instrument_baml() wraps the BAML client in a proxy that intercepts method calls. When a BAML function is called:
  1. The proxy detects the active trace (from @observe or trace())
  2. A span is created with the function name and arguments
  3. The real BAML function executes normally
  4. The span is completed with the structured result and token usage

What Gets Captured

See Also