DSPy
dspy.ailibraryself-hosted
DSPy is a self-hosted library in the Prompt Engineering layer of the AI stack. Declarative prompting that compiles to optimized programs from examples.
By Lattice editorial · Facts verified · method
- licence
- MIT
- language
- Python
- cost
- free
- owned by
- Applied Engineering
Verified 2026-09build refuses it from 2027-04
Use DSPy when
Compiling prompts into optimised programs from labelled examples.
Skip DSPy when
You have no examples and no way to score them.
Makes the prompt an artifact you can diff and test. — that is what this layer of the stack is answerable for. See the full Prompt Engineering section for the rest of the options.
Visit dspy.aiCompare with another toolBadge this entry
[](https://lattice.kunjshah.in/prompt-engineering/dspy)Quick answers
- Is DSPy open source?
- Yes. DSPy is open source under the MIT licence. It is free to use.
- What are the alternatives to DSPy?
- The closest alternatives to DSPy are TextGrad and PromptLayer.
Compared in
Reading on prompts
- Prompt, or fine-tune?Almost every 'the model does not know this' problem is a retrieval problem wearing a hat. Here is how to tell the difference before you spend a week on a training run.
- Context is a budget, not a containerThe instinct is to keep everything in case it is needed. The models are not filing systems, and past a certain length the middle of your context is doing nothing but costing money.
Alternatives to DSPy
Listed as an alternative to
- TextGradTextGradAutomatic prompt optimisation via textual feedback loops.Use when Automatic prompt optimisation via textual feedback loops.Skip when Optimising without an eval set is guessing.MIT · self-hosted · free
Also in prompts
- InstructorInstructorSchema-constrained extraction with automatic validation and retry.Use when Schema-validated extraction with typed retry and partial streaming.Skip when You need a hard token-level guarantee rather than validation.MIT · self-hosted · free
- HumanloopHumanloopPrompt versioning and evaluation for production teams.Use when Prompt versioning and evaluation run by a product team.Skip when Prompts or data cannot be sent to a vendor.proprietary · saas · usage-based
- GuidanceGuidanceConstrained generation by interleaving control flow and model output.Use when Constrained decoding with control flow interleaved into generation.Skip when You need better ergonomics for plain extraction.MIT · self-hosted · free
- PromptLayerPromptLayerPrompt registry with request logging and regression testing.Use when A prompt registry with request logging and regression tests.Skip when You need self-hosting.proprietary · saas · usage-based
- AgentaAgentaOpen-source prompt management with a playground and versioning.Use when Open-source prompt management with a playground and versioning.Skip when You need eval depth rather than prompt ergonomics.Apache-2.0 · self-hosted · free-tier
- PromptwatchPromptwatchPrompt regression tests and side-by-side comparison.Use when Prompt regression tests and side-by-side comparison.Skip when You need self-hosting.proprietary · saas · usage-based
- TextGradTextGradAutomatic prompt optimisation via textual feedback loops.Use when Automatic prompt optimisation via textual feedback loops.Skip when Optimising without an eval set is guessing.MIT · self-hosted · free
- OutlinesOutlinesConstrained generation that masks the token space to valid output.Use when Token-level constrained generation from a JSON schema or grammar.Skip when Post-hoc validation is enough for your use case.Apache-2.0 · self-hosted · free