> Version notice: This site documents BAML v0, the legacy DSL. BAML v1 is a separate, fully featured programming language in public beta. If the user intends to use BAML v1, ignore this site's content and use the BAML v1 documentation instead. If the intended version is unclear, clarify it before using this page. > For clean Markdown of any page, append .md to the page URL. For the complete documentation index, see https://docs.boundaryml.com/llms.txt. For MCP access, connect to https://docs.boundaryml.com/_mcp/server. > **Note** > > You can check out this repo: [https://github.com/BoundaryML/baml-examples/tree/main/ruby-starter](https://github.com/BoundaryML/baml-examples/tree/main/ruby-starter) To set up BAML with Ruby do the following: ### Install BAML VSCode Extension [https://marketplace.visualstudio.com/items?itemName=boundary.baml-extension](https://marketplace.visualstudio.com/items?itemName=boundary.baml-extension) * syntax highlighting * testing playground * prompt previews ### Install BAML **`bundle`** ```bash bundle bundle add baml sorbet-runtime ``` ### Add BAML to your existing project This will give you some starter BAML code in a `baml_src` directory. ```bash bundle exec baml-cli init ``` ### Generate Ruby code from `.baml` files ```bash bundle exec baml-cli generate ``` \` See [What is baml\_src](/guide/introduction/baml_src) to learn more about how this works. ![](/_fern-img/ebc4f2ef168af9b107c08eae516cd3949f3855bf2c379487e84cca9fdacd1474.webp) 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. > **Tip** > > Our [VSCode extension](https://marketplace.visualstudio.com/items?itemName=Boundary.baml-extension) automatically runs this command when you save a BAML file. ### Use a BAML function in Ruby! > **Error** > > If `baml_client` doesn't exist, make sure to run the previous step! #### Regular **`main.rb`** ```ruby 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' ``` #### Streaming **`stream_example.rb`** ```ruby stream_example.rb require_relative "baml_client/client" def example_stream(raw_resume) stream = Baml.Client.stream.ExtractResume(resume: raw_resume) stream.each do |msg| # msg is an instance of Baml::PartialTypes::Resume # defined in baml_client/partial_types puts msg.inspect end stream.get_final_response end example_stream 'Grace Hopper created COBOL' ```