What problem does it solve?
Many Ruby applications rely on brittle prompt engineering and ad-hoc LLM calls that are hard to test, version, and maintain; DSPy.rb replaces that by letting developers program LLM behavior with type-safe signatures and composable modules to produce reliable, testable AI features.
Core Features & Use Cases
- Type-safe Signatures: Define clear input/output contracts with runtime validation for extraction, classification, code generation, and multimodal tasks.
- Composable Modules & Predictors: Build reusable modules and pipelines using Predict, ChainOfThought, ReAct, and CodeAct for tasks like email triage, document analysis, and agent workflows.
- Provider Configuration & Observability: Templates for OpenAI, Anthropic, Gemini, Ollama, and OpenRouter plus examples for OpenTelemetry and Langfuse tracing, testing patterns, optimization (MIPROv2), and deployment best practices.
- Use Case Example: Implement an EmailClassification pipeline with a signature, a classifier module, ChainOfThought reasoning for difficult cases, and RSpec tests with mocked LLM responses.
Quick Start
Create an EmailClassification signature, implement a DSPy module that classifies support emails, and configure DSPy to use a local Ollama model or an OpenAI key for testing.