How Signatures, Modules, and Optimizers work together
mainDSPy's architecture is built on three core abstractions that decouple task logic from prompt engineering:
- Signatures: Declarative task specifications. They define the input/output behavior (the 'what') without specifying the prompt (the 'how'). They act as a contract for modules.
- Modules: Composable building blocks that encapsulate prompting strategies (e.g.,
Predict,ChainOfThought,ReAct). Modules are composed like neural network layers to build complex pipelines. - Optimizers: Self-improving engines (e.g.,
BootstrapFewShot). They take a module, a dataset, and a metric, then iteratively refine prompts and few-shot examples to maximize performance.