Ruby

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!
main.rb
require_relative "baml_client/client"
def example(raw_resume)
# r is an instance of Baml::Types::Resume, defined in baml_client/types
r = Baml.Client.ExtractResume(resume: raw_resume)
puts "ExtractResume response:"
puts r.inspect
end
example 'Grace Hopper created COBOL'