Puck.Backends.Baml (Puck v0.2.23)

Copy Markdown View Source

Backend implementation using BAML for structured outputs.

BAML provides type-safe structured outputs and is well-suited for building agentic loops. See the BAML documentation for details on defining functions and building agentic patterns.

Configuration

  • :function - (required) The BAML function name to call
  • :args - Custom arguments map or function
  • :args_format - How to build args: :auto, :messages, :text, or :raw
  • :client_registry - Runtime client registry for LLM provider configuration
  • :path - Path to BAML source files (defaults to baml_src)

Examples

# Basic usage
client = Puck.Client.new({Puck.Backends.Baml, function: "ExtractPerson"})
{:ok, result, _ctx} = Puck.call(client, "John is 30 years old")

# With custom args
client = Puck.Client.new({Puck.Backends.Baml,
  function: "ClassifyIntent",
  args: %{categories: ["question", "statement", "command"]}
})

Telemetry

When a call or stream returns an error, this backend emits a [:puck, :backend, :baml, :error] event. See Puck.Telemetry for details.