baml icon indicating copy to clipboard operation
baml copied to clipboard

[feat] Add support for Gleam

Open dylan-gluck opened this issue 3 months ago • 3 comments

Product

BAML

Problem Statement / Use Case

Gleam developers currently cannot use BAML for type-safe LLM interactions. Gleam is a growing language in the BEAM ecosystem that compiles to both Erlang and JavaScript, making it suitable for building reliable, concurrent systems. Adding Gleam support would enable:

  • Type-safe LLM integration in Gleam web services and applications
  • BEAM ecosystem adoption of BAML alongside existing Elixir support
  • Elixir/Erlang projects migrating to Gleam to continue using BAML

Proposed Solution

Add official Gleam language client support to BAML by implementing:

  1. Code Generator: Generate Gleam types and functions from BAML schemas

    • Location: engine/language_client_gleam/
    • Pattern: Follow existing TypeScript/Go/Ruby client implementations
  2. Runtime Library: Gleam package for runtime communication

    • HTTP client for BAML server interaction
    • Type-safe request/response handling
    • Streaming support via OTP actors
  3. CLI Integration: Add --target gleam to baml generate command

Implementation would follow the established pattern used for Go and Ruby clients, generating idiomatic Gleam code with proper type safety and error handling using Result types.

Alternative Solutions

  1. Community Package: Third-party Gleam wrapper around TypeScript/Python client

    • Pros: No maintenance burden on BAML team
    • Cons: Indirect integration, potential version mismatches, unofficial support
  2. JavaScript FFI: Use BAML TypeScript client via Gleam's JS compilation target

    • Pros: Reuses existing client
    • Cons: Only works on JS target, loses BEAM platform benefits

Additional Context

  • Gleam has official HTTP and JSON libraries suitable for client implementation
  • The language emphasizes type safety and reliability, aligning with BAML's goals
  • Implementation complexity is similar to the Ruby client (HTTP-based communication)

dylan-gluck avatar Sep 02 '25 18:09 dylan-gluck

related: https://github.com/emilsoman/baml_elixir

aaronvg avatar Sep 02 '25 18:09 aaronvg

Yes please! Gleam + Baml is the future

jamesjscully avatar Sep 09 '25 11:09 jamesjscully