DSPy replaces hand-crafted prompt strings with composable Python modules — Signatures, Predictors, and Optimizers — that compile to optimized prompts or fine-tuned weights. You define input/output specs once, and DSPy auto-tunes prompts via teleprompters like BootstrapFewShot and MIPROv2. In production, DSPy pipelines call LLM APIs, run evaluation loops, and serve compiled modules as inference endpoints — all of which need uptime monitoring. Vigilmon gives you HTTP health checks for your DSPy serving endpoints, heartbeat monitoring for optimization runs, SSL alerts for your inference APIs, and instant notifications when any part of your pipeline goes silent.
What You'll Set Up
- HTTP uptime monitor for your DSPy inference endpoint
- Cron heartbeat for long-running optimization (teleprompter) jobs
- SSL certificate expiry alerts for your DSPy API
- Alert channels for immediate notification on pipeline failures
Prerequisites
- DSPy installed (
pip install dspy) with at least one compiled module ready to serve - A FastAPI or similar HTTP wrapper around your DSPy predictor
- A free Vigilmon account
Step 1: Add a Health Endpoint to Your DSPy Serving Layer
DSPy modules are typically wrapped in a FastAPI or Flask app for inference. Add a /health route Vigilmon can probe before wiring up monitoring:
from fastapi import FastAPI
import dspy
app = FastAPI()
# Configure your LM
lm = dspy.LM("openai/gpt-4o-mini", api_key="sk-...")
dspy.configure(lm=lm)
# Load a compiled DSPy module
class RAGSignature(dspy.Signature):
"""Answer questions from retrieved context."""
context: str = dspy.InputField()
question: str = dspy.InputField()
answer: str = dspy.OutputField()
class RAGPipeline(dspy.Module):
def __init__(self):
self.predict = dspy.ChainOfThought(RAGSignature)
def forward(self, context, question):
return self.predict(context=context, question=question)
pipeline = RAGPipeline()
pipeline.load("compiled_rag.json") # Load optimized weights
@app.get("/health")
async def health():
return {"status": "ok", "module": "RAGPipeline", "compiled": True}
@app.post("/predict")
async def predict(context: str, question: str):
result = pipeline(context=context, question=question)
return {"answer": result.answer}
The /health endpoint confirms the module loaded successfully and the serving layer is up — not just the HTTP server.
Step 2: Monitor Your DSPy Inference Endpoint
With the health endpoint live, add a Vigilmon monitor:
- Log in to vigilmon.online and click Add Monitor.
- Set Type to
HTTP / HTTPS. - Enter your DSPy API URL:
https://dspy-api.yourdomain.com/health - Set Check interval to
1 minute. - Set Expected HTTP status to
200. - Click Save.
Vigilmon will alert you within a minute if the endpoint goes down, the module fails to load, or the LLM provider is unreachable at startup.
Step 3: Heartbeat Monitoring for Optimization Runs
DSPy teleprompters like BootstrapFewShot and MIPROv2 run multi-stage optimization loops that can take minutes to hours. These are background jobs that don't serve HTTP traffic. Use a Vigilmon cron heartbeat to confirm each optimization completes on schedule:
- In Vigilmon, click Add Monitor → Cron Heartbeat.
- Set the expected ping interval to match your optimization schedule (e.g.
60minutes for hourly re-optimization). - Copy the heartbeat URL (e.g.
https://vigilmon.online/heartbeat/abc123).
Add the ping to your optimization script after a successful run:
import httpx
import dspy
from dspy.teleprompt import BootstrapFewShot
def optimize_pipeline():
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)
trainset = load_training_data()
teleprompter = BootstrapFewShot(metric=answer_exact_match)
compiled_pipeline = teleprompter.compile(RAGPipeline(), trainset=trainset)
# Save the newly optimized module
compiled_pipeline.save("compiled_rag.json")
# Signal success to Vigilmon
httpx.get("https://vigilmon.online/heartbeat/abc123", timeout=5)
if __name__ == "__main__":
optimize_pipeline()
If the teleprompter crashes mid-run or the LLM API throttles the optimization loop, Vigilmon alerts after the expected interval passes — catching silent failures before a stale compiled module ships to production.
Step 4: Monitor Multiple Pipeline Stages
Complex DSPy programs chain multiple modules (retrieval, reranking, generation). Each stage may call a different LLM or embedding model. Expose per-stage health checks to isolate failures:
@app.get("/health/retriever")
async def retriever_health():
# Probe the retrieval index
try:
retriever = dspy.Retrieve(k=1)
retriever("test query")
return {"status": "ok", "stage": "retriever"}
except Exception as e:
return JSONResponse(status_code=503, content={"status": "error", "detail": str(e)})
@app.get("/health/generator")
async def generator_health():
# Confirm the LLM is reachable
try:
dspy.settings.lm("Respond with OK.", max_tokens=5)
return {"status": "ok", "stage": "generator"}
except Exception as e:
return JSONResponse(status_code=503, content={"status": "error", "detail": str(e)})
Add separate Vigilmon monitors for /health/retriever and /health/generator so you know which stage failed when an alert fires.
Step 5: SSL Certificate Alerts
If your DSPy inference API is served over HTTPS, enable SSL monitoring to catch certificate expiry before it breaks client integrations:
- Open the HTTP monitor for your DSPy endpoint (created in Step 2).
- Enable Monitor SSL certificate under the SSL section.
- Set Alert when certificate expires in less than
21 days. - Click Save.
LLM inference endpoints are often internal services — SSL expiry may go unnoticed until clients start throwing TLS errors mid-request.
Step 6: Configure Alert Channels
- Go to Alert Channels in Vigilmon and add Slack, email, or a webhook endpoint.
- Set Consecutive failures before alert to
2on each monitor — cold LLM API starts or brief network hiccups can cause single-probe timeouts. - Use Maintenance windows during redeployment after re-optimization:
# Before reloading a newly compiled module
curl -X POST https://vigilmon.online/api/maintenance \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"monitor_id": "abc123", "duration_minutes": 3}'
# Reload the inference service
systemctl restart dspy-api
# Maintenance window expires automatically
Summary
| Monitor | Target | What It Catches |
|---|---|---|
| HTTP endpoint | /health on inference service | Module load failure, LLM API unreachable |
| Per-stage health | /health/retriever, /health/generator | Isolated stage failure |
| Cron heartbeat | Heartbeat URL | Optimization crash, missed schedule |
| SSL certificate | DSPy API domain | Certificate expiry |
DSPy lets you systematically optimize multi-stage LLM pipelines with measurable quality metrics — but optimized modules are only as reliable as their serving infrastructure. With Vigilmon watching your DSPy inference endpoints, optimization heartbeats, and SSL certificates, you catch failures before they reach your users and keep your compiled pipelines running in production.