> ## Documentation Index
> Fetch the complete documentation index at: https://dspy-rb.ralak.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction

> What DSPy is, how Ruby on DSPy runs it, and a first example

After reading this guide, you will know:

* what DSPy and Ruby on DSPy are, and why the gem runs DSPy itself;
* what a few lines of dspy-rb look like;
* what a signature, a predictor and a prediction are.

## DSPy and Ruby on DSPy

[DSPy](https://dspy.ai) is a Python library for programming language models: you declare what a task takes in and gives back, and DSPy writes the prompt, calls the model and reads the reply back as typed values.

Ruby on DSPy runs DSPy from Ruby. The gem installs DSPy and runs it in a Python process of its own, so you write only Ruby.

Because every call runs in DSPy itself, the prompts are exactly the ones DSPy sends from Python, and [DSPy's docs](https://dspy.ai) explain the ideas behind them.

The gem is `dspy-rb`, and its module is `DSPyRb`. It's not [DSPy.rb](https://github.com/vicentereig/dspy.rb), a separate project that rewrites DSPy in Ruby.

## A first look

Say your app receives support tickets, and you want a model to label each one with a category and whether it's urgent. With Ruby on DSPy, this is all the code:

```ruby theme={"theme":"one-dark-pro"}
# frozen_string_literal: true

require "dspy-rb"

DSPyRb.configure do |config|
  config.lm = DSPyRb::LM["openai/gpt-4.1-mini"]
end

# Labels a support ticket with a category and an urgent flag.
class TriageTicket < DSPyRb::Signature
  CATEGORIES = %w[billing shipping returns account bug other].freeze

  instructions "Triage a customer's support ticket for the support team."

  input :subject, String
  input :body, String

  output :category, DSPyRb::Types::Literal[*CATEGORIES]
  output :urgent, DSPyRb::Types::Boolean
end

triage = DSPyRb::Predict[TriageTicket]
result = triage.call(
  subject: "Export is broken",
  body: "The export button crashes the app."
)

puts result.category
puts result.urgent
```

It prints the model's labels:

```text Output theme={"theme":"one-dark-pro"}
bug
true
```

`DSPyRb::LM[...]` names the language model DSPy calls, as `provider/model`. `config.lm` makes it the model every call uses.

A signature declares a task by its inputs and outputs. `TriageTicket` is a signature, written as a class. It has three parts:

* `instructions` tells the model the task, in a sentence.
* `input` declares what goes in: here, a ticket's subject and body.
* `output` declares what comes back: here, a category and an urgent flag.

Each output has a type, which tells DSPy what to ask the model for and how to read its reply. So `category` comes back as one of the names in `CATEGORIES`, and `urgent` as `true` or `false`. A reply that doesn't fit raises an error.

A signature can also be a string of names alone, such as `"question -> answer"`, when a task needs no types. Names before the arrow are inputs; names after it are outputs.

`DSPyRb::Predict[signature]` makes a predictor, which runs the signature: its `call` takes the inputs as keywords and asks the model. `call` returns a prediction, with a reader for each output.

There's no prompt in the code. DSPy writes it from the signature.

## Next

> [card] [Installation](https://dspy-rb.ralak.co/installation.md)
>
> Add the gem, install DSPy and make a first call.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.