dspy-anthropic 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d7d5d451d741b8dc70eed27bac00838a1de7eb7e099b1cc2510075f37abcec7
4
- data.tar.gz: 550bd7d0f4b8debc2e805a4e2d0ecd731e28cb3465838d8cc7e295d652077baa
3
+ metadata.gz: 31b0fc4e9033f850fe60e3bea0f99c90d055069d89736cdde636d4bd0e340d72
4
+ data.tar.gz: fcd89c5568e9227cc56aff466a0c3ec9f500fc7d288ae8ef48cc20bc31d814a9
5
5
  SHA512:
6
- metadata.gz: 3000dc2acf17bc454c3e53dc652213330bc2247a99d146f45f10ff1c08e2d4df6b2b622c7ae8239961af9f2e79fb2412a5039dbc85e704d314e33640f4315968
7
- data.tar.gz: f8ecfa9da285e14e0f048153452f1d964b5f380c6fca2b86a980bd0b50b561e9ed7a4e1d3b9311b0a92f5be3646f29a2d9fbd7e8b6aeb4a5e944b8aaaf101a18
6
+ metadata.gz: 699456b578d3f003c41c06bc106d52bcb8405569c48dfa11a5edbdc09e6522cae73f0c2b46453b5f213626ec4c6dcb3b3da8614f9f26f7a1f33f1076356dee8e
7
+ data.tar.gz: 4e3fb2612ae552b00cff15219e7a0e1b10a6be838586a9e4bc2b747e4737f0cf1197a357a0632c31b235f73620f04eca3595c5aa2d46a99fef48f34d66fa9af7
data/README.md CHANGED
@@ -3,59 +3,97 @@
3
3
  [![Gem Version](https://img.shields.io/gem/v/dspy)](https://rubygems.org/gems/dspy)
4
4
  [![Total Downloads](https://img.shields.io/gem/dt/dspy)](https://rubygems.org/gems/dspy)
5
5
  [![Build Status](https://img.shields.io/github/actions/workflow/status/vicentereig/dspy.rb/ruby.yml?branch=main&label=build)](https://github.com/vicentereig/dspy.rb/actions/workflows/ruby.yml)
6
- [![Documentation](https://img.shields.io/badge/docs-vicentereig.github.io%2Fdspy.rb-blue)](https://vicentereig.github.io/dspy.rb/)
6
+ [![Documentation](https://img.shields.io/badge/docs-oss.vicente.services%2Fdspy.rb-blue)](https://oss.vicente.services/dspy.rb/)
7
7
  [![Discord](https://img.shields.io/discord/1161519468141355160?label=discord&logo=discord&logoColor=white)](https://discord.gg/zWBhrMqn)
8
8
 
9
- > [!NOTE]
10
- > The core Prompt Engineering Framework is production-ready with
11
- > comprehensive documentation. I am focusing now on educational content on systematic Prompt Optimization and Context Engineering.
12
- > Your feedback is invaluable. if you encounter issues, please open an [issue](https://github.com/vicentereig/dspy.rb/issues). If you have suggestions, open a [new thread](https://github.com/vicentereig/dspy.rb/discussions).
13
- >
14
- > If you want to contribute, feel free to reach out to me to coordinate efforts: hey at vicente.services
15
- >
16
-
17
9
  **Build reliable LLM applications in idiomatic Ruby using composable, type-safe modules.**
18
10
 
19
- DSPy.rb is the Ruby-first surgical port of Stanford's [DSPy framework](https://github.com/stanfordnlp/dspy). It delivers structured LLM programming, prompt engineering, and context engineering in the language we love. Instead of wrestling with brittle prompt strings, you define typed signatures in idiomatic Ruby and compose workflows and agents that actually behave.
11
+ DSPy.rb is the Ruby port of Stanford's [DSPy](https://dspy.ai). Instead of wrestling with brittle prompt strings, you define typed signatures and let the framework handle the rest. Prompts become functions. LLM calls become predictable.
20
12
 
21
- **Prompts are just functions.** Traditional prompting is like writing code with string concatenation: it works until it doesn't. DSPy.rb brings you the programming approach pioneered by [dspy.ai](https://dspy.ai/): define modular signatures and let the framework deal with the messy bits.
13
+ ```ruby
14
+ require 'dspy'
22
15
 
23
- While we implement the same signatures, predictors, and optimization algorithms as the original library, DSPy.rb leans hard into Ruby conventions with Sorbet-based typing, ReAct loops, and production-ready integrations like non-blocking OpenTelemetry instrumentation.
16
+ DSPy.configure do |c|
17
+ c.lm = DSPy::LM.new('openai/gpt-4o-mini', api_key: ENV['OPENAI_API_KEY'])
18
+ end
24
19
 
25
- **What you get?** Ruby LLM applications that scale and don't break when you sneeze.
20
+ class Summarize < DSPy::Signature
21
+ description "Summarize the given text in one sentence."
26
22
 
27
- Check the [examples](examples/) and take them for a spin!
23
+ input do
24
+ const :text, String
25
+ end
28
26
 
29
- ## Your First DSPy Program
30
- ### Installation
27
+ output do
28
+ const :summary, String
29
+ end
30
+ end
31
31
 
32
- Add to your Gemfile:
32
+ summarizer = DSPy::Predict.new(Summarize)
33
+ result = summarizer.call(text: "DSPy.rb brings structured LLM programming to Ruby...")
34
+ puts result.summary
35
+ ```
36
+
37
+ That's it. No prompt templates. No JSON parsing. No prayer-based error handling.
38
+
39
+ ## Installation
33
40
 
34
41
  ```ruby
42
+ # Gemfile
35
43
  gem 'dspy'
44
+ gem 'dspy-openai' # For OpenAI, OpenRouter, or Ollama
45
+ # gem 'dspy-anthropic' # For Claude
46
+ # gem 'dspy-gemini' # For Gemini
47
+ # gem 'dspy-ruby_llm' # For 12+ providers via RubyLLM
36
48
  ```
37
49
 
38
- and
39
-
40
50
  ```bash
41
51
  bundle install
42
52
  ```
43
53
 
44
- ### Your First Reliable Predictor
54
+ ## Quick Start
45
55
 
46
- ```ruby
47
- require 'dspy'
56
+ ### Configure Your LLM
48
57
 
49
- # Configure DSPy globally to use your fave LLM (you can override per predictor).
58
+ ```ruby
59
+ # OpenAI
50
60
  DSPy.configure do |c|
51
61
  c.lm = DSPy::LM.new('openai/gpt-4o-mini',
52
62
  api_key: ENV['OPENAI_API_KEY'],
53
- structured_outputs: true) # Enable OpenAI's native JSON mode
63
+ structured_outputs: true)
64
+ end
65
+
66
+ # Anthropic Claude
67
+ DSPy.configure do |c|
68
+ c.lm = DSPy::LM.new('anthropic/claude-sonnet-4-20250514',
69
+ api_key: ENV['ANTHROPIC_API_KEY'])
70
+ end
71
+
72
+ # Google Gemini
73
+ DSPy.configure do |c|
74
+ c.lm = DSPy::LM.new('gemini/gemini-2.5-flash',
75
+ api_key: ENV['GEMINI_API_KEY'])
54
76
  end
55
77
 
56
- # Define a signature for sentiment classification - instead of writing a full prompt!
78
+ # Ollama (local, free)
79
+ DSPy.configure do |c|
80
+ c.lm = DSPy::LM.new('ollama/llama3.2')
81
+ end
82
+
83
+ # OpenRouter (200+ models)
84
+ DSPy.configure do |c|
85
+ c.lm = DSPy::LM.new('openrouter/deepseek/deepseek-chat-v3.1:free',
86
+ api_key: ENV['OPENROUTER_API_KEY'])
87
+ end
88
+ ```
89
+
90
+ ### Define a Signature
91
+
92
+ Signatures are typed contracts for LLM operations. Define inputs, outputs, and let DSPy handle the prompt:
93
+
94
+ ```ruby
57
95
  class Classify < DSPy::Signature
58
- description "Classify sentiment of a given sentence." # sets the goal of the underlying prompt
96
+ description "Classify sentiment of a given sentence."
59
97
 
60
98
  class Sentiment < T::Enum
61
99
  enums do
@@ -64,233 +102,130 @@ class Classify < DSPy::Signature
64
102
  Neutral = new('neutral')
65
103
  end
66
104
  end
67
-
68
- # Structured Inputs: makes sure you are sending only valid prompt inputs to your model
105
+
69
106
  input do
70
107
  const :sentence, String, description: 'The sentence to analyze'
71
108
  end
72
109
 
73
- # Structured Outputs: your predictor will validate the output of the model too.
74
110
  output do
75
- const :sentiment, Sentiment, description: 'The sentiment of the sentence'
76
- const :confidence, Float, description: 'A number between 0.0 and 1.0'
111
+ const :sentiment, Sentiment
112
+ const :confidence, Float
77
113
  end
78
114
  end
79
115
 
80
- # Wire it to the simplest prompting technique: a prediction loop.
81
- classify = DSPy::Predict.new(Classify)
82
- # it may raise an error if you mess the inputs or your LLM messes the outputs.
83
- result = classify.call(sentence: "This book was super fun to read!")
84
-
85
- puts result.sentiment # => #<Sentiment::Positive>
86
- puts result.confidence # => 0.85
87
- ```
88
-
89
- Save this as `examples/first_predictor.rb` and run it with:
116
+ classifier = DSPy::Predict.new(Classify)
117
+ result = classifier.call(sentence: "This book was super fun to read!")
90
118
 
91
- ```bash
92
- bundle exec ruby examples/first_predictor.rb
119
+ result.sentiment # => #<Sentiment::Positive>
120
+ result.confidence # => 0.92
93
121
  ```
94
122
 
95
- ### Sibling Gems
123
+ ### Chain of Thought
96
124
 
97
- DSPy.rb ships multiple gems from this monorepo so you can opt into features with heavier dependency trees (e.g., datasets pull in Polars/Arrow, MIPROv2 requires `numo-*` BLAS bindings) only when you need them. Add these alongside `dspy`:
125
+ For complex reasoning, use `ChainOfThought` to get step-by-step explanations:
98
126
 
99
- | Gem | Description | Status |
100
- | --- | --- | --- |
101
- | `dspy-schema` | Exposes `DSPy::TypeSystem::SorbetJsonSchema` for downstream reuse. (Still required by the core `dspy` gem; extraction lets other projects depend on it directly.) | **Stable** (v1.0.0) |
102
- | `dspy-openai` | Packages the OpenAI/OpenRouter/Ollama adapters plus the official SDK guardrails. Install whenever you call `openai/*`, `openrouter/*`, or `ollama/*`. [Adapter README](https://github.com/vicentereig/dspy.rb/blob/main/lib/dspy/openai/README.md) | **Stable** (v1.0.0) |
103
- | `dspy-anthropic` | Claude adapters, streaming, and structured-output helpers behind the official `anthropic` SDK. [Adapter README](https://github.com/vicentereig/dspy.rb/blob/main/lib/dspy/anthropic/README.md) | **Stable** (v1.0.0) |
104
- | `dspy-gemini` | Gemini adapters with multimodal + tool-call support via `gemini-ai`. [Adapter README](https://github.com/vicentereig/dspy.rb/blob/main/lib/dspy/gemini/README.md) | **Stable** (v1.0.0) |
105
- | `dspy-code_act` | Think-Code-Observe agents that synthesize and execute Ruby safely. (Add the gem or set `DSPY_WITH_CODE_ACT=1` before requiring `dspy/code_act`.) | **Stable** (v1.0.0) |
106
- | `dspy-datasets` | Dataset helpers plus Parquet/Polars tooling for richer evaluation corpora. (Toggle via `DSPY_WITH_DATASETS`.) | **Stable** (v1.0.0) |
107
- | `dspy-evals` | High-throughput evaluation harness with metrics, callbacks, and regression fixtures. (Toggle via `DSPY_WITH_EVALS`.) | **Stable** (v1.0.0) |
108
- | `dspy-miprov2` | Bayesian optimization + Gaussian Process backend for the MIPROv2 teleprompter. (Install or export `DSPY_WITH_MIPROV2=1` before requiring the teleprompter.) | **Stable** (v1.0.0) |
109
- | `dspy-gepa` | `DSPy::Teleprompt::GEPA`, reflection loops, experiment tracking, telemetry adapters. (Install or set `DSPY_WITH_GEPA=1`.) | **Stable** (v1.0.0) |
110
- | `gepa` | GEPA optimizer core (Pareto engine, telemetry, reflective proposer). | **Stable** (v1.0.0) |
111
- | `dspy-o11y` | Core observability APIs: `DSPy::Observability`, async span processor, observation types. (Install or set `DSPY_WITH_O11Y=1`.) | **Stable** (v1.0.0) |
112
- | `dspy-o11y-langfuse` | Auto-configures DSPy observability to stream spans to Langfuse via OTLP. (Install or set `DSPY_WITH_O11Y_LANGFUSE=1`.) | **Stable** (v1.0.0) |
113
- | `dspy-deep_search` | Production DeepSearch loop with Exa-backed search/read, token budgeting, and instrumentation (Issue #163). | **Stable** (v1.0.0) |
114
- | `dspy-deep_research` | Planner/QA orchestration atop DeepSearch plus the memory supervisor used by the CLI example. | **Stable** (v1.0.0) |
115
- | `sorbet-toon` | Token-Oriented Object Notation (TOON) codec, prompt formatter, and Sorbet mixins for BAML/TOON Enhanced Prompting. [Sorbet::Toon README](https://github.com/vicentereig/dspy.rb/blob/main/lib/sorbet/toon/README.md) | **Alpha** (v0.1.0) |
127
+ ```ruby
128
+ solver = DSPy::ChainOfThought.new(MathProblem)
129
+ result = solver.call(problem: "If a train travels 120km in 2 hours, what's its speed?")
116
130
 
117
- **Provider adapters:** Add `dspy-openai`, `dspy-anthropic`, and/or `dspy-gemini` next to `dspy` in your Gemfile depending on which `DSPy::LM` providers you call. Each gem already depends on the official SDK (`openai`, `anthropic`, `gemini-ai`), and DSPy auto-loads the adapters when the gem is present—no extra `require` needed.
131
+ result.reasoning # => "Speed = Distance / Time = 120km / 2h = 60km/h"
132
+ result.answer # => "60 km/h"
133
+ ```
118
134
 
119
- Set the matching `DSPY_WITH_*` environment variables (see `Gemfile`) to include or exclude each sibling gem when running Bundler locally (for example `DSPY_WITH_GEPA=1` or `DSPY_WITH_O11Y_LANGFUSE=1`). Refer to `adr/013-dependency-tree.md` for the full dependency map and roadmap.
120
- ### Access to 200+ Models Across 5 Providers
135
+ ### ReAct Agents
121
136
 
122
- DSPy.rb provides unified access to major LLM providers with provider-specific optimizations:
137
+ Build agents that use tools to accomplish tasks:
123
138
 
124
139
  ```ruby
125
- # OpenAI (GPT-4, GPT-4o, GPT-4o-mini, GPT-5, etc.)
126
- DSPy.configure do |c|
127
- c.lm = DSPy::LM.new('openai/gpt-4o-mini',
128
- api_key: ENV['OPENAI_API_KEY'],
129
- structured_outputs: true) # Native JSON mode
130
- end
140
+ class SearchTool < DSPy::Tools::Tool
141
+ tool_name "search"
142
+ description "Search for information"
131
143
 
132
- # Google Gemini (Gemini 1.5 Pro, Flash, Gemini 2.0, etc.)
133
- DSPy.configure do |c|
134
- c.lm = DSPy::LM.new('gemini/gemini-2.5-flash',
135
- api_key: ENV['GEMINI_API_KEY'],
136
- structured_outputs: true) # Native structured outputs
137
- end
144
+ input do
145
+ const :query, String
146
+ end
138
147
 
139
- # Anthropic Claude (Claude 3.5, Claude 4, etc.)
140
- DSPy.configure do |c|
141
- c.lm = DSPy::LM.new('anthropic/claude-sonnet-4-5-20250929',
142
- api_key: ENV['ANTHROPIC_API_KEY'],
143
- structured_outputs: true) # Tool-based extraction (default)
144
- end
148
+ output do
149
+ const :results, T::Array[String]
150
+ end
145
151
 
146
- # Ollama - Run any local model (Llama, Mistral, Gemma, etc.)
147
- DSPy.configure do |c|
148
- c.lm = DSPy::LM.new('ollama/llama3.2') # Free, runs locally, no API key needed
152
+ def call(query:)
153
+ # Your search implementation
154
+ { results: ["Result 1", "Result 2"] }
155
+ end
149
156
  end
150
157
 
151
- # OpenRouter - Access to 200+ models from multiple providers
152
- DSPy.configure do |c|
153
- c.lm = DSPy::LM.new('openrouter/deepseek/deepseek-chat-v3.1:free',
154
- api_key: ENV['OPENROUTER_API_KEY'])
155
- end
158
+ toolset = DSPy::Tools::Toolset.new(tools: [SearchTool.new])
159
+ agent = DSPy::ReAct.new(signature: ResearchTask, tools: toolset, max_iterations: 5)
160
+ result = agent.call(question: "What's the latest on Ruby 3.4?")
156
161
  ```
157
162
 
158
- ## What You Get
159
-
160
- **Developer Experience:** Official clients, multimodal coverage, and observability baked in.
161
- <details>
162
- <summary>Expand for everything included</summary>
163
-
164
- - LLM provider support using official Ruby clients:
165
- - [OpenAI Ruby](https://github.com/openai/openai-ruby) with vision model support
166
- - [Anthropic Ruby SDK](https://github.com/anthropics/anthropic-sdk-ruby) with multimodal capabilities
167
- - [Google Gemini API](https://ai.google.dev/) with native structured outputs
168
- - [Ollama](https://ollama.com/) via OpenAI compatibility layer for local models
169
- - **Multimodal Support** - Complete image analysis with DSPy::Image, type-safe bounding boxes, vision-capable models
170
- - Runtime type checking with [Sorbet](https://sorbet.org/) including T::Enum and union types
171
- - Type-safe tool definitions for ReAct agents
172
- - Comprehensive instrumentation and observability
173
- </details>
174
-
175
- **Core Building Blocks:** Predictors, agents, and pipelines wired through type-safe signatures.
176
- <details>
177
- <summary>Expand for everything included</summary>
178
-
179
- - **Signatures** - Define input/output schemas using Sorbet types with T::Enum and union type support
180
- - **Predict** - LLM completion with structured data extraction and multimodal support
181
- - **Chain of Thought** - Step-by-step reasoning for complex problems with automatic prompt optimization
182
- - **ReAct** - Tool-using agents with type-safe tool definitions and error recovery
183
- - **Module Composition** - Combine multiple LLM calls into production-ready workflows
184
- </details>
185
-
186
- **Optimization & Evaluation:** Treat prompt optimization like a real ML workflow.
187
- <details>
188
- <summary>Expand for everything included</summary>
189
-
190
- - **Prompt Objects** - Manipulate prompts as first-class objects instead of strings
191
- - **Typed Examples** - Type-safe training data with automatic validation
192
- - **Evaluation Framework** - Advanced metrics beyond simple accuracy with error-resilient pipelines
193
- - **MIPROv2 Optimization** - Advanced Bayesian optimization with Gaussian Processes, multiple optimization strategies, auto-config presets, and storage persistence
194
- </details>
195
-
196
- **Production Features:** Hardened behaviors for teams shipping actual products.
197
- <details>
198
- <summary>Expand for everything included</summary>
199
-
200
- - **Reliable JSON Extraction** - Native structured outputs for OpenAI and Gemini, Anthropic tool-based extraction, and automatic strategy selection with fallback
201
- - **Type-Safe Configuration** - Strategy enums with automatic provider optimization (Strict/Compatible modes)
202
- - **Smart Retry Logic** - Progressive fallback with exponential backoff for handling transient failures
203
- - **Zero-Config Langfuse Integration** - Set env vars and get automatic OpenTelemetry traces in Langfuse
204
- - **Performance Caching** - Schema and capability caching for faster repeated operations
205
- - **File-based Storage** - Optimization result persistence with versioning
206
- - **Structured Logging** - JSON and key=value formats with span tracking
207
- </details>
208
-
209
- ## Recent Achievements
210
-
211
- DSPy.rb has gone from experimental to production-ready in three fast releases.
212
- <details>
213
- <summary>Expand for the full changelog highlights</summary>
214
-
215
- ### Foundation
216
- - ✅ **JSON Parsing Reliability** - Native OpenAI structured outputs with adaptive retry logic and schema-aware fallbacks
217
- - ✅ **Type-Safe Strategy Configuration** - Provider-optimized strategy selection and enum-backed optimizer presets
218
- - ✅ **Core Module System** - Predict, ChainOfThought, ReAct with type safety (add `dspy-code_act` for Think-Code-Observe agents)
219
- - ✅ **Production Observability** - OpenTelemetry, New Relic, and Langfuse integration
220
- - ✅ **Advanced Optimization** - MIPROv2 with Bayesian optimization, Gaussian Processes, and multi-mode search
221
-
222
- ### Recent Advances
223
- - ✅ **MIPROv2 ADE Integrity (v0.29.1)** - Stratified train/val/test splits, honest precision accounting, and enum-driven `--auto` presets with integration coverage
224
- - ✅ **Instruction Deduplication (v0.29.1)** - Candidate generation now filters repeated programs so optimization logs highlight unique strategies
225
- - ✅ **GEPA Teleprompter (v0.29.0)** - Genetic-Pareto reflective prompt evolution with merge proposer scheduling, reflective mutation, and ADE demo parity
226
- - ✅ **Optimizer Utilities Parity (v0.29.0)** - Bootstrap strategies, dataset summaries, and Layer 3 utilities unlock multi-predictor programs on Ruby
227
- - ✅ **Observability Hardening (v0.29.0)** - OTLP exporter runs on a single-thread executor preventing frozen SSL contexts without blocking spans
228
- - ✅ **Documentation Refresh (v0.29.x)** - New GEPA guide plus ADE optimization docs covering presets, stratified splits, and error-handling defaults
229
- </details>
230
-
231
- **Current Focus Areas:** Closing the loop on production patterns and community adoption ahead of v1.0.
232
- <details>
233
- <summary>Expand for the roadmap</summary>
234
-
235
- ### Production Readiness
236
- - 🚧 **Production Patterns** - Real-world usage validation and performance optimization
237
- - 🚧 **Ruby Ecosystem Integration** - Rails integration, Sidekiq compatibility, deployment patterns
238
-
239
- ### Community & Adoption
240
- - 🚧 **Community Examples** - Real-world applications and case studies
241
- - 🚧 **Contributor Experience** - Making it easier to contribute and extend
242
- - 🚧 **Performance Benchmarks** - Comparative analysis vs other frameworks
243
- </details>
244
-
245
- **v1.0 Philosophy:** v1.0 lands after battle-testing, not checkbox bingo. The API is already stable; the milestone marks production confidence.
163
+ ## What's Included
164
+
165
+ **Core Modules**: Predict, ChainOfThought, ReAct agents, and composable pipelines.
166
+
167
+ **Type Safety**: Sorbet-based runtime validation. Enums, unions, nested structs—all work.
168
+
169
+ **Multimodal**: Image analysis with `DSPy::Image` for vision-capable models.
170
+
171
+ **Observability**: Zero-config Langfuse integration via OpenTelemetry. Non-blocking, production-ready.
246
172
 
173
+ **Optimization**: MIPROv2 (Bayesian optimization) and GEPA (genetic evolution) for prompt tuning.
174
+
175
+ **Provider Support**: OpenAI, Anthropic, Gemini, Ollama, and OpenRouter via official SDKs.
247
176
 
248
177
  ## Documentation
249
178
 
250
- 📖 **[Complete Documentation Website](https://vicentereig.github.io/dspy.rb/)**
179
+ **[Full Documentation](https://oss.vicente.services/dspy.rb/)** — Getting started, core concepts, advanced patterns.
251
180
 
252
- ### LLM-Friendly Documentation
181
+ **[llms.txt](https://oss.vicente.services/dspy.rb/llms.txt)** LLM-friendly reference for AI assistants.
253
182
 
254
- For LLMs and AI assistants working with DSPy.rb:
255
- - **[llms.txt](https://vicentereig.github.io/dspy.rb/llms.txt)** - Concise reference optimized for LLMs
256
- - **[llms-full.txt](https://vicentereig.github.io/dspy.rb/llms-full.txt)** - Comprehensive API documentation
183
+ ### Claude Skill
257
184
 
258
- ### Getting Started
259
- - **[Installation & Setup](docs/src/getting-started/installation.md)** - Detailed installation and configuration
260
- - **[Quick Start Guide](docs/src/getting-started/quick-start.md)** - Your first DSPy programs
261
- - **[Core Concepts](docs/src/getting-started/core-concepts.md)** - Understanding signatures, predictors, and modules
185
+ A [Claude Skill](https://github.com/vicentereig/dspy-rb-skill) is available to help you build DSPy.rb applications:
262
186
 
263
- ### Prompt Engineering
264
- - **[Signatures & Types](docs/src/core-concepts/signatures.md)** - Define typed interfaces for LLM operations
265
- - **[Predictors](docs/src/core-concepts/predictors.md)** - Predict, ChainOfThought, ReAct, and more
266
- - **[Modules & Pipelines](docs/src/core-concepts/modules.md)** - Compose complex multi-stage workflows
267
- - **[Multimodal Support](docs/src/core-concepts/multimodal.md)** - Image analysis with vision-capable models
268
- - **[Examples & Validation](docs/src/core-concepts/examples.md)** - Type-safe training data
269
- - **[Rich Types](docs/src/advanced/complex-types.md)** - Sorbet type integration with automatic coercion for structs, enums, and arrays
270
- - **[Composable Pipelines](docs/src/advanced/pipelines.md)** - Manual module composition patterns
187
+ ```bash
188
+ # Claude Code
189
+ git clone https://github.com/vicentereig/dspy-rb-skill ~/.claude/skills/dspy-rb
190
+ ```
271
191
 
272
- ### Prompt Optimization
273
- - **[Evaluation Framework](docs/src/optimization/evaluation.md)** - Advanced metrics beyond simple accuracy
274
- - **[Prompt Optimization](docs/src/optimization/prompt-optimization.md)** - Manipulate prompts as objects
275
- - **[MIPROv2 Optimizer](docs/src/optimization/miprov2.md)** - Advanced Bayesian optimization with Gaussian Processes
276
- - **[GEPA Optimizer](docs/src/optimization/gepa.md)** *(beta)* - Reflective mutation with optional reflection LMs
192
+ For Claude.ai Pro/Max, download the [skill ZIP](https://github.com/vicentereig/dspy-rb-skill/archive/refs/heads/main.zip) and upload via Settings > Skills.
277
193
 
278
- ### Context Engineering
279
- - **[Tools](docs/src/core-concepts/toolsets.md)** - Tool wieldint agents.
280
- - **[Agentic Memory](docs/src/core-concepts/memory.md)** - Memory Tools & Agentic Loops
281
- - **[RAG Patterns](docs/src/advanced/rag.md)** - Manual RAG implementation with external services
194
+ ## Examples
282
195
 
283
- ### Production Features
284
- - **[Observability](docs/src/production/observability.md)** - Zero-config Langfuse integration with a dedicated export worker that never blocks your LLMs
285
- - **[Storage System](docs/src/production/storage.md)** - Persistence and optimization result storage
286
- - **[Custom Metrics](docs/src/advanced/custom-metrics.md)** - Proc-based evaluation logic
196
+ The [examples/](examples/) directory has runnable code for common patterns:
287
197
 
198
+ - Sentiment classification
199
+ - ReAct agents with tools
200
+ - Image analysis
201
+ - Prompt optimization
288
202
 
203
+ ```bash
204
+ bundle exec ruby examples/first_predictor.rb
205
+ ```
206
+
207
+ ## Optional Gems
289
208
 
209
+ DSPy.rb ships sibling gems for features with heavier dependencies. Add them as needed:
290
210
 
211
+ | Gem | What it does |
212
+ | --- | --- |
213
+ | `dspy-datasets` | Dataset helpers, Parquet/Polars tooling |
214
+ | `dspy-evals` | Evaluation harness with metrics and callbacks |
215
+ | `dspy-miprov2` | Bayesian optimization for prompt tuning |
216
+ | `dspy-gepa` | Genetic-Pareto prompt evolution |
217
+ | `dspy-o11y-langfuse` | Auto-configure Langfuse tracing |
218
+ | `dspy-code_act` | Think-Code-Observe agents |
219
+ | `dspy-deep_search` | Production DeepSearch with Exa |
291
220
 
221
+ See [the full list](https://oss.vicente.services/dspy.rb/getting-started/installation/) in the docs.
292
222
 
223
+ ## Contributing
293
224
 
225
+ Feedback is invaluable. If you encounter issues, [open an issue](https://github.com/vicentereig/dspy.rb/issues). For suggestions, [start a discussion](https://github.com/vicentereig/dspy.rb/discussions).
226
+
227
+ Want to contribute code? Reach out: hey at vicente.services
294
228
 
295
229
  ## License
296
- This project is licensed under the MIT License.
230
+
231
+ MIT License.
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DSPy
4
+ module Anthropic
5
+ # Raised when Anthropic blocks output due to content filtering/safety policies
6
+ class ContentFilterError < DSPy::LM::AdapterError; end
7
+ end
8
+ end
@@ -139,6 +139,8 @@ module DSPy
139
139
  raise DSPy::LM::AdapterError, "Anthropic rate limit exceeded: #{error_msg}. Please wait and try again."
140
140
  elsif error_msg.include?('authentication') || error_msg.include?('API key')
141
141
  raise DSPy::LM::AdapterError, "Anthropic authentication failed: #{error_msg}. Check your API key."
142
+ elsif error_msg.include?('content filtering') || error_msg.include?('blocked')
143
+ raise DSPy::Anthropic::ContentFilterError, "Anthropic content filtered: #{error_msg}"
142
144
  else
143
145
  # Generic error handling
144
146
  raise DSPy::LM::AdapterError, "Anthropic adapter error: #{e.message}"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DSPy
4
4
  module Anthropic
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dspy/anthropic/version'
4
+ require 'dspy/anthropic/errors'
4
5
 
5
6
  require 'dspy/anthropic/guardrails'
6
7
  DSPy::Anthropic::Guardrails.ensure_anthropic_installed!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dspy-anthropic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vicente Reig Rincón de Arellano
@@ -48,6 +48,7 @@ files:
48
48
  - LICENSE
49
49
  - README.md
50
50
  - lib/dspy/anthropic.rb
51
+ - lib/dspy/anthropic/errors.rb
51
52
  - lib/dspy/anthropic/guardrails.rb
52
53
  - lib/dspy/anthropic/lm/adapters/anthropic_adapter.rb
53
54
  - lib/dspy/anthropic/version.rb