DSPy: The End of Prompt Engineering - Kevin Madura, AlixPartners
By AI Engineer
Key Concepts
- DSPI (Declarative Synthesis of Programs with Interfaces): A framework for building modular software using LLMs as first-class citizens, focusing on what a program should do rather than how.
- Program-Centric Approach: DSPI prioritizes building proper Python programs with LLMs, moving away from iterative prompt engineering.
- Modularity & Composability: DSPI encourages breaking down logic into reusable modules for a cohesive and optimizable structure.
- Iterative Optimization: DSPI supports automated prompt refinement using optimizers and feedback loops to improve performance.
- Transferability & Future-Proofing: The framework’s design allows for easy model swapping without rewriting core logic, ensuring adaptability as LLM capabilities evolve.
- DSPIHub: A platform for sharing and collaborating on pre-optimized DSPI programs.
DSPI Overview & Core Principles
DSPI is a declarative framework designed to facilitate the construction of modular software by treating Large Language Models (LLMs) as fundamental components. It allows developers to focus on defining the desired outcome of a program – its what – rather than dictating the specific implementation steps – its how. This approach contrasts with traditional prompt engineering, which often involves iterative tweaking and can lead to fragile and difficult-to-maintain solutions. DSPI emphasizes encoding intent in a way that remains adaptable as LLM capabilities advance. The framework is not an optimizer in itself, but rather a set of programming abstractions that can be optimized.
Building Blocks & Technical Components
The core of DSPI revolves around several key technical concepts. Signatures define the input and output types of functions, utilizing Pyantic-based classes or shorthand notation. These field names are directly incorporated into the prompts sent to the LLM. These signatures are encapsulated within Modules for organization and reusability. Adapters translate these signatures into prompt formats like JSON or BAML, allowing for customization to optimize performance for specific models. Testing suggests BAML adapters can improve performance by 5-10% compared to JSON. Tools are created by exposing Python functions to the LLM via DSPI’s tool interface. Attachments provide a library for handling various file types (PDFs, images, etc.).
Real-World Applications & Use Cases
DSPI’s versatility is demonstrated through a range of applications. Initial examples included sentiment classification, PDF processing (extracting information from SEC Form 4 filings), multimodal analysis (processing images and text), contract analysis (identifying clauses), time entry standardization, and help message categorization. A central demonstration focuses on processing a “dump” of diverse files – contracts, images, SEC filings – to categorize and process them appropriately. This mirrors common client scenarios involving unstructured data requiring specific handling. Specific examples include automatically identifying and processing SEC filings, summarizing contracts, interpreting city infrastructure images (street signs), and correcting time entries (performance improved from 86% to 89% through optimization). A hypothetical example involves identifying invoice pages within larger documents.
Iterative Optimization & the Optimizer
DSPI supports iterative prompt optimization using algorithms like Myrow. This process involves providing input-output data pairs, defining performance metrics, and running the optimizer to refine prompts. The optimizer effectively finds latent requirements that might not have been explicitly specified, acting as a “poor man’s deep learning” approach. This optimization process requires a relatively small dataset (10-100 examples) and can significantly improve performance. The output of the optimizer is a serialized module that can be saved or deployed directly. LLMs can also act as judges, identifying adversarial examples that optimizers then leverage to find optimal prompts.
Workflow & Processing Pipeline
A typical DSPI workflow involves loading a file, formatting it using the attachment library, classifying its type using a dedicated function, and then executing specific processing logic based on that classification. For example, with PDFs, this involves converting the PDF to a list of images, classifying each page, and then using those classifications to detect document structure (main document, schedules, exhibits). The system can handle multiple image inputs to improve classification accuracy. DSPI also supports asynchronous processing for improved performance.
DSPIHub & Community Collaboration
DSPIHub, a newly created platform, allows users to share pre-optimized DSPI programs, fostering reuse and collaboration, similar to Hugging Face. This enables developers to leverage existing solutions and build upon the work of others.
Conclusion
DSPI offers a powerful and flexible framework for building modular software with LLMs. By shifting the focus from prompt engineering to program construction, DSPI promotes maintainability, transferability, and adaptability. The iterative optimization capabilities and the emergence of DSPIHub further enhance its value, positioning it as a valuable tool for rapid prototyping, complex data processing, and leveraging the evolving capabilities of LLMs. It’s not necessarily a replacement for traditional machine learning, but a complementary approach for specific LLM-based tasks, potentially reducing costs through prompt optimization and model selection.
Chat with this Video
AI-PoweredLoad the transcript when you're ready to chat so the initial page stays lighter.
Related Videos

Building Great Agent Skills: The Missing Manual
AI Engineer

AI System Design: From Idea to Production - Apoorva Joshi, MongoDB
AI Engineer

When All Context Matters: Extended Cache Augmented Generation - Luis Romero-Sevilla, Orbis
AI Engineer

Bypassing the Multimodal Tax: Hybrid RAG, SQL RRF & UI Telemetry - Abed Matini, Ogilvy
AI Engineer

OpenClaw in Your Hand: Building a Physical AI Terminal - Lech Kalinowski, Callstack
AI Engineer

GPT 5.6 Mythos Level Intelligence
Prompt Engineering

GPT 5.6 SOL: TBH, IT'S OKAY.. I have SERIOUS CONCERNS.
AICodeKing