Skip to main content
skill CX Codex

dspy-production-deployment — Claude Code skill: how to install

Prepares DSPy 3.2.1 pipelines for production by configuring safe caching, state-only JSON persistence, async calls, and output streaming.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add OmidZamani/dspy-skills --skill dspy-production-deployment -a claude-code
Open on GitHub

What dspy-production-deployment does

This skill guides agents through deploying DSPy applications with runtime safeguards. DSPy caches calls in memory and on disk by default, where disk caches deserialize via pickle. The skill enforces dspy.configure_cache(restrict_pickle=True) or specifies explicit allowlists through safe_types to stop insecure object loading.

Artifact handling focuses on exporting model state via compiled.save(path, save_program=False) into JSON rather than dumping Python objects. For inference workloads, the guide supplies patterns for asynchronous runs with acall() and response streaming using dspy.streamify(). It also activates token tracking with track_usage=True.

Saving the entire program with cloudpickle creates code execution risks if files come from unverified origins. The instructions target DSPy 3.2.1 compatibility.

What it helps with

  • restrict disk cache deserialization using safe allowlists
  • export compiled DSPy program state to JSON without pickle
  • enable async module execution using acall()
  • stream model generation chunks with dspy.streamify()

Example prompts for the agent

  • Configure DSPy cache hardening with restrict_pickle enabled
  • Show how to export my compiled DSPy pipeline state into JSON
  • Convert this Predict module to stream chunks using streamify

How to install dspy-production-deployment

1Skills CLI (Vercel)

npx skills add OmidZamani/dspy-skills --skill dspy-production-deployment -a claude-code

2Manually: put the files in place

~/.claude/skills/dspy-production-deployment/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dspy-production-deployment/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about dspy-production-deployment

How to install dspy-production-deployment in Claude Code?

Run npx skills add OmidZamani/dspy-skills --skill dspy-production-deployment -a claude-code in your terminal.

What does dspy-production-deployment do?

It instructs the agent on safe production practices for DSPy, including cache allowlisting, state serialization, async execution, and token tracking.

Why use state-only JSON instead of whole-program saving?

Full program exports use cloudpickle, which executes arbitrary code during loading. State-only JSON loaded into an instantiated module avoids binary deserialization risks.

Source text

SKILL.md · MIT
---
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/

© OmidZamani · MIT · OmidZamani/dspy-skills

Similar skills

All skills for AI and ML →

From the same set23

dspy-signature-designer Turns a task description into a typed DSPy signature with declared inputs and outputs. Useful when model replies must fit a fixed schema. CX Codex +1 ★ 124repo stars dspy-reasoning-modules Guides configuration of DSPy 3.2.1 reasoning modules including RLM, ProgramOfThought, CodeAct, and Parallel. Useful for sandboxed code and long documents. CX Codex +1 ★ 124repo stars dspy-react-agent-builder This skill guides you through building DSPy ReAct agents that call tools to handle multi-step tasks. Use it for workflows involving retrieval, calculations, or answers based on external data. CX Codex +1 ★ 124repo stars dspy-rag-pipeline Builds retrieval-augmented generation pipelines powered by ColBERTv2 that can be systematically optimized. Use when questions require searching across your own document corpus and grounding answers in retrieved facts. CX Codex +1 ★ 124repo stars dspy-output-refinement-constraints This skill shows how to validate DSPy outputs, refine them with dspy.Refine, and choose among candidates with dspy.BestOfN. Use it when generated results must meet format or content rules. CX Codex +1 ★ 124repo stars dspy-optimizer-selection Helps you pick a DSPy optimizer that fits your data and budget, from LabeledFewShot up to GEPA and BetterTogether. Useful when you don't know where to start compiling. CX Codex +1 ★ 124repo stars dspy-optimize-anything Guides AI agents through GEPA reflective evolutionary search for code, prompts, configs, and text artifacts using diagnostic feedback. CX Codex +1 ★ 124repo stars dspy-miprov2-optimizer This skill guides MIPROv2 optimization of DSPy programs, searching for instruction and few-shot demo combinations with Bayesian optimization. Use it to tune a program against training data. CX Codex +1 ★ 124repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor