dspy-ruby

dspy-ruby is a skill for Claude Code, Codex from roberto-mello/lavra. It costs 35 tokens per session (5,949 once invoked), scanned A, a copy of dspy-ruby, MIT.

A Ruby framework for building applications that use language models with typed inputs and outputs. DSPy.rb lets developers define reusable components and improve prompts using data instead of repeatedly guessing at wording.

In plain words
What is it for?
Use it to implement AI features, agent systems, prompt-based workflows, typed model calls, testing, observability, and data-driven prompt optimization in Ruby.
Why use it?
LLM code can be difficult to test and can silently return the wrong shape of data. Typed interfaces and modular components make these interactions easier to check and reuse.

Skill for Claude CodeCodex

Part of the lavra plugin — 23 skills, 18 commands, 1 hook, 1 MCP server shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/roberto-mello/lavra/dspy-ruby
Any agent
npx skills add roberto-mello/lavra --skill dspy-ruby
Clone the repo
git clone --depth 1 https://github.com/roberto-mello/lavra

Made for: Claude Code, Codex.

Or install lavra, the plugin that ships this one along with the rest of its 23 skills, 18 commands, 1 hook, 1 MCP server.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for dspy-ruby

README.md
[![agentmods](https://agentmods.dev/badge/skills/roberto-mello/lavra/dspy-ruby.svg)](https://agentmods.dev/skills/roberto-mello/lavra/dspy-ruby)
Your own site
<a href="https://agentmods.dev/skills/roberto-mello/lavra/dspy-ruby"><img src="https://agentmods.dev/badge/skills/roberto-mello/lavra/dspy-ruby.svg" alt="Measured on agentmods" height="20"></a>
Per session 35 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,949 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 94% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00035 $0.05949
Opus 5 $0.00017 $0.02975
Sonnet 5 $0.00007 $0.01190
Haiku 4.5 $0.00003 $0.00595

Measured 3d ago against content hash e23d7d4d43af, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

dspy-ruby scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

The scan reads SKILL.md. This mod also ships 3 executable files (assets/config-template.rb, assets/module-template.rb, assets/signature-template.rb), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

94% identical to dspy-ruby — 6 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

plugins/lavra/skills/optional/dspy-ruby/SKILL.md · 742 lines

How it starts

The opening of the file, as written. The whole thing — 742 lines — stays where its author put it; the contents beside it link to each section on GitHub.

DSPy.rb

Build LLM apps like you build software. Type-safe, modular, testable.

DSPy.rb brings software engineering best practices to LLM development. Instead of tweaking prompts, define what you want with Ruby types and let DSPy handle the rest.

Overview

DSPy.rb is a Ruby framework for building language model applications with programmatic prompts. It provides:

  • Type-safe signatures — Define inputs/outputs with Sorbet types
  • Modular components — Compose and reuse LLM logic
  • Automatic optimization — Use data to improve prompts, not guesswork
  • Production-ready — Built-in observability, testing, and error handling

Core Concepts

1. Signatures

Define interfaces between your app and LLMs using Ruby types:

class EmailClassifier < DSPy::Signature
  description "Classify customer support emails by category and priority"

  class Priority < T::Enum
    enums do
      Low = new('low')
      Medium = new('medium')
      High = new('high')
      Urgent = new('urgent')
    end
  end

  input do
    const :email_content, String
    const :sender, String
  end

  output do
    const :category, String
    const :priority, Priority  # Type-safe enum with defined values
    const :confidence, Float
  end
end

2. Modules

Build complex workflows from simple building blocks:

  • Predict — Basic LLM calls with signatures
  • ChainOfThought — Step-by-step reasoning
  • ReAct — Tool-using agents
  • CodeAct — Dynamic code generation agents (install the dspy-code_act gem)

3. Tools & Toolsets

Create type-safe tools for agents with comprehensive Sorbet support:

# Enum-based tool with automatic type conversion
class CalculatorTool < DSPy::Tools::Base
  tool_name 'calculator'
  tool_description 'Performs arithmetic operations with type-safe enum inputs'

  class Operation < T::Enum
    enums do
      Add = new('add')
      Subtract = new('subtract')
      Multiply = new('multiply')
      Divide = new('divide')
    end
  end

  sig { params(operation: Operation, num1: Float, num2: Float).returns(T.any(Float, String)) }
  def call(operation:, num1:, num2:)
    case operation
    when Operation::Add then num1 + num2
    when Operation::Subtract then num1 - num2
    when Operation::Multiply then num1 * num2
    when Operation::Divide
      return "Error: Division by zero" if num2 == 0
      num1 / num2
    end
  end
end

# Multi-tool toolset with rich types
class DataToolset < DSPy::Tools::Toolset
  toolset_name "data_processing"

  class Format < T::Enum
    enums do
      JSON = new('json')
      CSV = new('csv')
      XML = new('xml')
    end
  end

  tool :convert, description: "Convert data between formats"
  tool :validate, description: "Validate data structure"

  sig { params(data: String, from: Format, to: Format).returns(String) }
  def convert(data:, from:, to:)
    "Converted from #{from.serialize} to #{to.serialize}"
  end

  sig { params(data: String, format: Format).returns(T::Hash[String, T.any(String, Integer, T::Boolean)]) }
  def validate(data:, format:)
    { valid: true, format: format.serialize, row_count: 42, message: "Data validation passed" }
  end
end

Read the full file on GitHub · 742 lines

Files

What ships with it

8 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 742 lines · 35 tokens per session scan A e23d7d4d43af

Subscribe to this mod's changes

dspy-ruby is a skill published in the GitHub repository roberto-mello/lavra (50 stars, last pushed 2mo ago), licensed MIT. It adds 35 tokens to every session and 5,949 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. It is 94% identical to dspy-ruby, differing in 6 lines, and is treated as a copy.