Programming Language Models from Zero to Production
Introduction: The End of Prompt Engineering as We Know It
Chapter 1: What Is DSPy and Why It Matters
- The Prompting Crisis
- From Prompting to Programming
- The DSPy Philosophy
- How DSPy Fits in the Ecosystem
Chapter 2: Installation and Your First Program
- Installing DSPy
- Configuring Your Language Model
- Your First Signature and Prediction
- Understanding the Output
- Switching Between Models
- A Complete First Program
- Migration Notes from Older Versions
Chapter 3: Signatures in Depth
- String-Based Signatures
- Class-Based Signatures
- Input Fields and Output Fields
- Type Annotations and Pydantic Integration
- Signature Mutation and Composition
- Signature Introspection
- Designing Effective Signatures
Chapter 4: Core Modules
- dspy.Predict: Basic Prediction
- dspy.ChainOfThought: Step-by-Step Reasoning
- dspy.ProgramOfThought: Code-Assisted Reasoning
- dspy.MultiChainComparison: Comparing Outputs
- dspy.BestOfN and dspy.Refine: Output Refinement
- dspy.Parallel: Concurrent Execution
- Choosing the Right Module
Chapter 5: Composing Custom Modules
- The dspy.Module Base Class
- Building Your First Compound Module
- Forward Method Design Patterns
- Nested Modules and Sub-modules
- Module Inspection and Introspection
- Deep Copy and State Management
Chapter 6: Language Models and Configuration
- The dspy.LM Interface
- OpenAI, Anthropic, and Google Providers
- Local Models and OpenAI-Compatible Endpoints
- Context Management with dspy.context()
- Caching and Performance
- Tracking Usage and Costs
- Adapter Selection
Chapter 7: Evaluation and Metrics
- Writing Metric Functions
- The dspy.Evaluate Class
- Built-in Metrics
- LLM-as-a-Judge Evaluation
- Debugging with inspect_history()
- Composite Metrics
- Evaluation Best Practices
Chapter 8: Optimizers (Teleprompters)
- The Optimization Paradigm
- BootstrapFewShot Family
- COPRO: Instruction Optimization
- MIPROv2: Joint Instruction and Demo Search
- GEPA: Reflective Prompt Evolution
- SIMBA and Other Specialized Optimizers
- Choosing the Right Optimizer
- Saving and Loading Compiled Programs
Chapter 9: Retrieval-Augmented Generation (RAG)
- The dspy.Retrieve Module
- ColBERTv2 Integration
- Building a Basic RAG Pipeline
- Multi-Hop RAG
- Optimizing RAG Programs
- Custom Retriever Integration
Chapter 10: Agents and Tool Use
- The ReAct Paradigm
- dspy.ReAct Module
- Defining Tools as Functions
- Building Production Agents
- Advanced Tool Patterns
Chapter 11: Structured Outputs and Type Safety
- Typed Predictors
- Pydantic Models in Signatures
- JSON Schema Generation
- Output Validation Strategies
- Complex Nested Structures
Chapter 12: Advanced Patterns and Workflows
- Assertions and Constraints (Refine Module)
- Multimodal Programs with Images and Audio
- Conversation History Management
- Async and Streaming Support
- MCP Integration
- Caching Strategies for Production
Chapter 13: Production Deployment
- Saving and Loading Optimized Programs
- FastAPI Deployment
- MLflow Integration
- Caching Strategies
- Monitoring and Observability
Chapter 14: Performance Optimization and Best Practices
- Cost Optimization
- Latency Reduction
- Error Handling Patterns
- Testing DSPy Programs
- Common Pitfalls and Anti-Patterns
Chapter 15: Real-World Projects
- Project 1: Intelligent Customer Service Agent
- Project 2: Multi-Document Research Assistant
- Project 3: Automated Code Review System
