ratacat/claude-skills/dspy-ruby
Claude Code and agent skill by ratacat/claude-skills
- community
Checking that the SKILL.md file is still in the repository.
This skill should be used when working with DSPy.rb, a Ruby framework for building type-safe, composable LLM applications. Use this when implementing predictable AI features, creating LLM signatures and modules, configuring language model providers (OpenAI, Anthropic, Gemini, Ollama), building agent systems with tools, optimizing prompts, or testing LLM-powered functionality in Ruby applications.
Install
npx vskill@latest install ratacat/claude-skills/dspy-rubySKILL.md
DSPy.rb Expert
Overview
DSPy.rb is a Ruby framework that enables developers to program LLMs, not prompt them. Instead of manually crafting prompts, define application requirements through type-safe, composable modules that can be tested, optimized, and version-controlled like regular code.
This skill provides comprehensive guidance on:
- Creating type-safe signatures for LLM operations
- Building composable modules and workflows
- Configuring multiple LLM providers
- Implementing agents with tools
- Testing and optimizing LLM applications
- Production deployment patterns
Core Capabilities
1. Type-Safe Signatures
Create input/output contracts for LLM operations with runtime type checking.
When to use: Defining any LLM task, from simple classification to complex analysis.
Quick reference:
Templates: See assets/signature-template.rb for comprehensive examples including:
- Basic signatures with multiple field types
- Vision signatures for multimodal tasks
- Sentiment analysis signatures
- Code generation signatures
Best practices:
- Always provide clear, specific descriptions
- Use enums for constrained outputs
- Include field descriptions with
desc:parameter - Prefer specific types over generic String when possible
Full documentation: See references/core-concepts.md sections on Signatures and Type Safety.
2. Composable Modules
Build reusable, chainable modules that encapsulate LLM operations.
When to use: Implementing any LLM-powered feature, especially complex multi-step workflows.
Quick reference:
Templates: See assets/module-template.rb for comprehensive examples including:
- Basic modules with single predictors
- Multi-step pipelines that chain modules
- Modules with conditional logic
- Error handling and retry patterns
- Stateful modules with history
- Caching implementations
Module composition: Chain modules together to create complex workflows:
Full documentation: See references/core-concepts.md sections on Modules and Module Composition.
3. Multiple Predictor Types
Choose the right predictor for your task:
Predict: Basic LLM inference with type-safe inputs/outputs
ChainOfThought: Adds automatic reasoning for improved accuracy
ReAct: Tool-using agents with iterative reasoning
CodeAct: Dynamic code generation (requires dspy-code_act gem)
When to use each:
- Predict: Simple tasks, classification, extraction
- ChainOfThought: Complex reasoning, analysis, multi-step thinking
- ReAct: Tasks requiring external tools (search, calculation, API calls)
- CodeAct: Tasks best solved with generated code
Full documentation: See references/core-concepts.md section on Predictors.
4. LLM Provider Configuration
Support for OpenAI, Anthropic Claude, Google Gemini, Ollama, and OpenRouter.
Quick configuration examples:
Templates: See assets/config-template.rb for comprehensive examples including:
- Environment-based configuration
- Multi-model setups for different tasks
- Configuration with observability (OpenTelemetry, Langfuse)
- Retry logic and fallback strategies
- Budget tracking
- Rails initializer patterns
Provider compatibility matrix:
| Feature | OpenAI | Anthropic | Gemini | Ollama | |
|---|---|---|---|---|---|
| Structured Output | ✅ | ✅ | ✅ | ✅ | |
| Vision (Images) | ✅ | ✅ | ✅ | ⚠️ Limited | |
| Image URLs | ✅ | ❌ | ❌ | ❌ | |
| Tool Calling | ✅ | ✅ | ✅ | Varies |
Cost optimization strategy:
- Development: Ollama (free) or gpt-4o-mini (cheap)
- Testing: gpt-4o-mini with temperature=0.0
- Production simple tasks: gpt-4o-mini, claude-3-haiku, gemini-1.5-flash
- Production complex tasks: gpt-4o, claude-3-5-sonnet, gemini-1.5-pro
Full documentation: See references/providers.md for all configuration options, provider-specific features, and troubleshooting.
5. Multimodal & Vision Support
Process images alongside text using the unified DSPy::Image interface.
Quick reference:
Image loading methods:
Provider support:
- OpenAI: Full support including URLs
- Anthropic, Gemini: Base64 or file loading only
- Ollama: Limited multimodal depending on model
Full documentation: See references/core-concepts.md section on Multimodal Support.
6. Testing LLM Applications
Write standard RSpec tests for LLM logic.
Quick reference:
Testing patterns:
- Mock LLM responses for unit tests
- Use VCR for deterministic API testing
- Test type safety and validation
- Test edge cases (empty inputs, special characters, long texts)
- Integration test complete workflows
Full documentation: See references/optimization.md section on Testing.
7. Optimization & Improvement
Automatically improve prompts and modules using optimization techniques.
MIPROv2 optimization:
A/B testing different approaches:
Full documentation: See references/optimization.md section on Optimization.
8. Observability & Monitoring
Track performance, token usage, and behavior in production.
OpenTelemetry integration:
Langfuse tracing:
Custom monitoring:
- Token tracking
- Performance monitoring
- Error rate tracking
- Custom logging
Full documentation: See references/optimization.md section on Observability.
Quick Start Workflow
For New Projects
- Install DSPy.rb and provider gems:
- Configure LLM provider (see
assets/config-template.rb):
- Create a signature (see
assets/signature-template.rb):
- Create a module (see
assets/module-template.rb):
- Use the module:
- Add tests (see
references/optimization.md):
For Rails Applications
- Add to Gemfile:
- Create initializer at
config/initializers/dspy.rb(seeassets/config-template.rbfor full example):
- Create modules in
app/llm/directory:
- Use in controllers/services:
Common Patterns
Pattern: Multi-Step Analysis Pipeline
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationPassed, 70 of 100Effective. 1 run. Evaluated 8 months ago.
Source
- SKILL.md in the repositoryCheckingskills/dspy-ruby/SKILL.md
Popularity
- Repository stars
- 56
- Repository forks
- 9
- 7-day trend score
- 20
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ratacat/claude-skills/dspy-ruby)