dspy-production-deployment
/dspy-production-deployment
Use for deploying DSPy with save/load, configure_cache, restrict_pickle, track_usage, async execution, streaming, and production runtime controls.
- Author
- OmidZamani ↗
- Repository
- dspy-skills ↗
- Licence
- MIT
- Last repository change
- 23.06.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 1
- HTML comments
- 0
- URLs in SKILL.md
- 5
No signals detected. Repository changed on 23.06.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
- 1 scripts in this package. Review them before installing, as Claude may execute them.
Scripts: example.py
What it does and when to use it
Use for deploying DSPy with save/load, configure_cache, restrict_pickle, track_usage, async execution, streaming, and production runtime controls.
Original author description
Use for deploying DSPy with save/load, configure_cache, restrict_pickle, track_usage, async execution, streaming, and production runtime controls.
How it works
- Goal
- Cache Hardening
- Save and Load
- Usage Tracking
- Async Execution
- Streaming
- Production Checklist
- Official Documentation
SKILL.md preview
---
name: dspy-production-deployment
version: "1.0.0"
dspy-compatibility: "3.2.1"
tags: ["production"]
requires-extras: []
description: Use for deploying DSPy with save/load, configure_cache, restrict_pickle, track_usage, async execution, streaming, and production runtime controls.
allowed-tools:
- Read
- Write
- Glob
- Grep
---
# DSPy Production Deployment
## Goal
Prepare a DSPy program for repeatable, observable, scalable, and safer production execution.
## Cache Hardening
DSPy enables memory and disk caches by default. Disk cache deserialization uses pickle unless restricted. Enable the allowlist mode in production:
```python
import dspy
dspy.configure_cache(restrict_pickle=True)
```
Register trusted custom cache types only when needed:
```python
dspy.configure_cache(
restrict_pickle=True,
safe_types=[MyResult, Metadata],
)
```
Disable a cache layer explicitly when a deployment cannot persist data or requires fresh model responses:
```python
dspy.configure_cache(
enable_disk_cache=False,
enable_memory_cache=True,
)
```
## Save and Load
Prefer state-only JSON for readable, safer artifacts:
```python
compiled.save("./artifacts/program.json", save_program=False)
loaded = MyProgram()
loaded.load("./artifacts/program.json")
```
Use whole-program save only for trusted artifacts. It uses cloudpickle:
```python
compiled.save("./artifacts/program/", save_program=True)
loaded = dspy.load("./artifacts/program/")
```
Keep the DSPy major version compatible when loading saved programs.
## Usage Tracking
```python
dspy.configure(
lm=dspy.LM("openai/gpt-4o-mini"),
track_usage=True,
)
prediction = program(question="What is DSPy?")
print(prediction.get_lm_usage())
```
Cached calls return no new token usage.
## Async Execution
Most built-in modules support `acall()`:
```python
import asyncio
async def main():
prediction = await program.acall(question="What is DSPy?")
print(prediction.answer)
asyncio.run(main())
```
Implement `aforward()` for custom async modules. Use `dspy.asyncify(program)` only when adapting a synchronous callable is the right boundary.
## Streaming
```python
import asyncio
import dspy
stream_program = dspy.streamify(
dspy.Predict("question -> answer"),
stream_listeners=[
dspy.streaming.StreamListener(signature_field_name="answer"),
],
)
async def main():
async for chunk in stream_program(question="Explain DSPy briefly."):
print(chunk)
asyncio.run(main())
```
For looped modules such as ReAct, set `allow_reuse=True` on listeners for repeated fields. Cache hits yield the final `Prediction` without replaying token chunks.
## Production Checklist
1. Pin the stable DSPy series.
2. Use state-only JSON unless whole-program pickle is necessary and trusted.
3. Enable `restrict_pickle=True`.
4. Record usage, latency, errors, and traces.
5. Load-test async and streaming paths separately.
6. Use [dspy-debugging-observability](../dspy-debugging-observability/SKILL.md) for MLflow and callbacks.
## Official Documentation
- **Production guide**: https://dspy.ai/production/
- **Cache tutorial**: https://dspy.ai/tutorials/cache/
- **Saving tutorial**: https://dspy.ai/tutorials/saving/
- **Async tutorial**: https://dspy.ai/tutorials/async/
- **Streaming tutorial**: https://dspy.ai/tutorials/streaming/
Files in this package (2)
- SKILL.md 3 KB
- example.py 1 KB
Versions
The database has no other skills named dspy-production-deployment.
Identical content appears in 1 other GitHub folders. We show one copy with the highest score.
Database snapshot: 13.11.2026 · package version 392a4d5fce38 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100dspy-mcp-tool-integration
Use for MCP tools with DSPy, Model Context Protocol servers, dspy.Tool.from_mcp_tool, and ReAct agents over MCP-compatible tools. - 100dspy-output-refinement-constraints
Use for dspy.Refine, dspy.BestOfN, output constraints, validation, reward functions, and iterative output refinement. - 95dspy-ruby
This skill should be used when working with DSPy.rb, a Ruby framework for type-safe, composable LLM applications. - 100dspy-advanced-workflow
Build DSPy 3.2.x programs through spec, program, metric and baseline; extend to optimization and export when requested and justified by task budget. Orchestrates the other four DSPy skills (dspy-fundamentals, dspy-evaluation-harness, dspy-gepa-optimizer, dspy-rlm-module) in the… - 100dspy-fundamentals
Write idiomatic DSPy 3.2.x programs — typed Signatures, dspy.Module subclasses, Predict/ChainOfThought/ReAct/ProgramOfThought, and save/load. Use this when starting any new DSPy project or when fixing non-idiomatic DSPy code (hard-coded prompts, ad-hoc string templates, untyped… - 100dspy
DSPy 2.5+ for programming (not prompting) LMs. Covers Signatures, Modules (Predict, ChainOfThought, ReAct, Retrieve), compilers/optimizers (BootstrapFewShot, MIPROv2, BootstrapFinetune), retrievers, evaluation, and production deployment of compiled programs. USE WHEN: user…