For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Help on Discord
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
HomeGuideExamplesBAML ReferencePlaygroundAgents.mdChangelog
  • Introduction
    • What is BAML?
    • Why BAML?
    • What's the baml_src folder
    • What's baml_client
  • Installation: Editors
    • VSCode Extension
    • Cursor Extension
    • JetBrains IDEs
    • Zed
    • Claude Code
    • Others
  • Installation: Language
    • Python
    • Typescript
    • Go
    • Ruby
    • Rust
    • REST API (other languages)
    • Elixir
  • Framework Integration
  • Development
    • Environment Variables
    • Terminal Logs
    • Upgrade BAML versions
  • BAML Basics
    • Prompting with BAML
    • Switching LLMs
    • Testing functions
    • Streaming
    • Multi-Modal (Images / Audio)
    • Error Handling
    • Configuring Timeouts
    • Concurrent Calls
    • AbortSignal / Cancellation
  • BAML Advanced
    • Collector (track tokens)
    • LLM Client Registry
    • Dynamic Types
    • Reusing Prompt Snippets
    • Prompt Caching / Message Role Metadata
    • Checks and Asserts
    • Modular API
    • Prompt Optimization
  • Boundary Cloud
  • Comparisons
    • BAML vs Langchain
    • BAML vs Marvin
    • BAML vs Ai-SDK
    • BAML vs OpenAI SDK
    • BAML vs Pydantic
    • Contact
Help on Discord
LogoLogo
Installation: Language

Ruby

Was this page helpful?
Edit this page
Previous

Rust

Set up BAML with Rust
Next
Built with
You can check out this repo: https://github.com/BoundaryML/baml-examples/tree/main/ruby-starter

To set up BAML with Ruby do the following:

1

Install BAML VSCode Extension

https://marketplace.visualstudio.com/items?itemName=boundary.baml-extension

  • syntax highlighting
  • testing playground
  • prompt previews
2

Install BAML

bundle
$bundle add baml sorbet-runtime
3

Add BAML to your existing project

This will give you some starter BAML code in a baml_src directory.

$bundle exec baml-cli init
4

Generate Ruby code from .baml files

$bundle exec baml-cli generate

` See What is baml_src to learn more about how this works.

As fun as writing BAML is, we want you be able to leverage BAML with existing ruby modules. This command gives you a ruby module that is a type-safe interface to every BAML function.

Our VSCode extension automatically runs this command when you save a BAML file.

5

Use a BAML function in Ruby!

If baml_client doesn’t exist, make sure to run the previous step!
Regular
Streaming
main.rb
1require_relative "baml_client/client"
2
3def example(raw_resume)
4 # r is an instance of Baml::Types::Resume, defined in baml_client/types
5 r = Baml.Client.ExtractResume(resume: raw_resume)
6
7 puts "ExtractResume response:"
8 puts r.inspect
9end
10
11example 'Grace Hopper created COBOL'