DSPy
Stanford's framework for programming — not prompting — LLMs: compile, optimize, and auto-tune modular AI systems.
DSPy
DSPy (Declarative Self-improving Python) is Stanford NLP's framework for algorithmically optimizing LLM prompts and weights. Instead of hand-crafting prompts, you write Python modules with typed signatures; DSPy's optimizers ("teleprompters") automatically generate, evaluate, and refine the best prompts for your task and model.
Key Features
- Signatures — declare input/output fields with descriptions; DSPy handles prompt construction
- Modules —
dspy.Predict,dspy.ChainOfThought,dspy.ReAct,dspy.ProgramOfThought, and more - Optimizers —
BootstrapFewShot,MIPRO,BayesianSignatureOptimizerauto-tune prompts with labeled examples - Assertions — declare constraints and DSPy retries until they're satisfied
- Model-agnostic — works with OpenAI, Anthropic, Ollama, HuggingFace, Databricks, and 20+ providers
- Composable — nest modules into complex multi-stage pipelines that optimize end-to-end
Quick Start
pip install dspy
import dspy
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)
class QA(dspy.Signature):
question: str = dspy.InputField()
answer: str = dspy.OutputField(desc="concise factual answer")
predict = dspy.Predict(QA)
result = predict(question="What year was Python created?")
print(result.answer)
Install via ai-supply
npx ai-supply add dspy-llm-programming
Curated mirror of the open-source DSPy project (MIT). Install upstream from the repository.
Compromise signals — malicious or tampered code (leaked secrets, backdoors, a dropped executable) — reduce the score, and known dependency CVEs carry a bounded penalty (they warrant review but never QUARANTINE — update the dependency to clear). Other dangerous-by-capability traits are risk surface, expected for some capabilities. Every finding is mapped to its OWASP control below.
Findings mapped to the OWASP Top 10 for LLM Applications (2025) and the OWASP Machine Learning Security Top 10. Expand any flagged control for the exact findings — compromise reduces the score; expected/risk-surface do not, except a known CVE, which carries a small bounded penalty (high/critical → Review).
The same gate an agent runs before installing (POST /api/v1/trust/dspy-llm-programming/check). Click a policy:
Consume DSPy programmatically. Authenticate with an API key or session — see Authorize an agent.
# Agents: CHECK BEFORE YOU INSTALL (no auth) — score, grade, level, capability manifest
curl https://ai-supply.store/api/v1/trust/dspy-llm-programming
# Gate against your org policy (returns { pass, violations })
curl -X POST https://ai-supply.store/api/v1/trust/dspy-llm-programming/check \
-H "Content-Type: application/json" \
-d '{"minGrade":"B","denyPermissions":["shell"],"denyUnknownEgress":true}'
# CLI
npx ai-supply add dspy-llm-programming
# REST (install → download)
curl -X POST https://ai-supply.store/api/v1/listings/dspy-llm-programming/install \
-H "Authorization: Bearer $AIM_KEY"
# MCP tool
install_listing({ "slug": "dspy-llm-programming" })OpenAPI spec →Curated mirror — latest upstream source. See the repository for tagged releases.