Structure & Data

DSPy Signatures

Specify agent behaviour as declarative typed signatures and modules; compile prompts and few-shot examples automatically against a metric.

Problem

When prompts are hand-written strings glued into application code, they drift over time and break in ways that are expensive to track down. A wording change that helps one model hurts another; small edits to phrasing change behaviour without anyone noticing; every pipeline reinvents the same prompt-engineering loop with no shared discipline. Without a way to express what each step expects and produces in a structured form, the team has no compiler to lean on and no metric-driven way to know whether a prompt change is an improvement or a regression.

Solution

Define each step as a typed signature (input fields → output fields). Compose signatures into modules. Run a teleprompter (optimizer) that generates few-shot examples and refines instructions against a held-out metric. The compiled artefact replaces hand-tuned prompts.

When to use

  • Hand-crafted prompts are brittle and drift across model versions.
  • A held-out metric exists that the optimizer can refine against.
  • Composing pipelines from typed signatures fits the team's mental model.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related