Skip to content

Learning path · Programmatic Prompting · 30

DSPy Signatures

Typed input-output contracts in DSPy that specify fields, docstrings, and constraints for each module step.

Why it matters

  • Makes pipeline interfaces explicit and optimizable.
  • Reduces ad hoc string formatting across teams.
  • Enables teleprompters to target specific fields.

Key ideas

  • Input fields
  • Output fields
  • Docstring hints

A signature declares what a module consumes and produces—question, context, answer; or claim, evidence, verdict. Docstrings guide both the base LM and the optimizer. Signatures mirror good API design: narrow types, clear semantics, minimal leakage between steps. When migrating from handwritten prompts, extract the implicit schema first; optimization works best on stable interfaces. Keep signatures stable across releases so optimized prompts remain comparable; breaking field names resets optimization gains. Ship only after eval gates pass on representative production failures.

Updated 2026-08-09 · Full learning path