Skip to main content

Generate DSPy Signatures from any prompt using a DSPy meta-program

Project description

AutoSignature

Generate typed dspy.Signature classes with dspy.RLM.
Explore the Documentation »
Report Bug Request Feature

Table of Contents
  1. About
  2. Quick Start
  3. SDK Message Formats
  4. DataFrame Example
  5. API
  6. Contributing
  7. License

About

AutoSignature uses dspy.RLM to inspect a prompt or dataset and generate a complete dspy.Signature subclass.

  • Automatic signature design — Infers instructions, inputs, outputs, field descriptions, and types
  • Dataset-aware generation — Profiles DataFrame columns, distributions, and representative rows
  • Ready to use — Returns signatures compatible with dspy.Predict, dspy.ChainOfThought, and other DSPy modules
  • Exportable — Renders generated signatures as Python source with to_source()

Requires Python 3.12+, DSPy 3.2+, and Deno for the RLM sandbox.

(back to top)

Quick Start

Install

Install AutoSignature with uv (recommended):

uv add dspy-auto-signature

Or with pip:

pip install dspy-auto-signature

Basic Usage

import dspy
import dspy_auto_signature as das

das.configure(
    lm=dspy.LM("openai/gpt-4o"),
    sub_lm=dspy.LM("openai/gpt-4o-mini"),
)

signature = das.generate(
    "Given an article, produce a concise summary and three key takeaways."
)

print(signature.to_source())

dspy.configure(lm=dspy.LM("openai/gpt-4o-mini"))
summarize = dspy.ChainOfThought(signature.to_signature())
result = summarize(article="...")

(back to top)

SDK Message Formats

AutoSignature accepts message arrays from popular LLM SDKs. Pass your existing conversation history directly — no conversion needed.

OpenAI SDK

import dspy
import dspy_auto_signature as das

das.configure(
    lm=dspy.LM("openai/gpt-4o"),
    sub_lm=dspy.LM("openai/gpt-4o-mini"),
)

messages = [
    {"role": "system", "content": "You are a technical writer who produces clear documentation."},
    {"role": "user", "content": "Write a README for a Python CLI tool that converts CSV to JSON."},
]

signature = das.generate(messages)
print(signature.to_source())

Anthropic SDK

messages = [
    {"role": "user", "content": "Analyze the sentiment of customer reviews."},
    {"role": "assistant", "content": "I'll classify each review as positive, negative, or neutral."},
]

signature = das.generate(messages)

Google Gemini SDK

contents = [
    {"role": "user", "parts": [{"text": "Extract key entities from this legal contract."}]},
    {"role": "model", "parts": [{"text": "I'll identify parties, dates, and obligations."}]},
]

signature = das.generate(contents)

LiteLLM / OpenAI-Compatible

Any SDK that produces OpenAI-style [{"role": "...", "content": "..."}] arrays works out of the box — including LiteLLM, Azure OpenAI, Ollama, and vLLM.

See example_sdk.py for a complete runnable example.

DataFrame Example

Install with the pandas extra to get pandas:

uv add "dspy-auto-signature[pandas]"

Or with pip:

pip install "dspy-auto-signature[pandas]"

Datasets are profiled before generation so the RLM can use column names, types, distributions, and representative rows when designing the signature.

import dspy
import pandas as pd
import dspy_auto_signature as das

das.configure(
    lm=dspy.LM("openai/gpt-4o"),
    sub_lm=dspy.LM("openai/gpt-4o-mini"),
)

tickets = pd.DataFrame(
    [
        {"message": "Server is down", "urgency": "high"},
        {"message": "Please update my profile", "urgency": "low"},
        {"message": "Payment failed", "urgency": "high"},
    ]
)

signature = das.generate(
    tickets,
    task_hint="Classify support ticket urgency from the message",
)

print(signature.to_source())

(back to top)

API

generate(source, task_hint=None, *, input_hints=None, output_hints=None)

Generates a dspy.Signature subclass from prompt material or tabular data.

Parameter Type Description
source Any Prompt string, SDK message array (OpenAI, Anthropic, Google, LiteLLM), DataFrame, list of dictionaries, or list of dspy.Example objects
task_hint str | None Optional task description, especially useful for identifying dataset targets
input_hints dict[str, str] | None Input field descriptions to supplement or override generated descriptions
output_hints dict[str, str] | None Output field descriptions to supplement or override generated descriptions

Supported input formats:

  • Raw strings (system prompts, task descriptions)
  • OpenAI SDK message arrays: [{"role": "system", "content": "..."}, {"role": "user", "content": "..."}]
  • Anthropic SDK message arrays: [{"role": "user", "content": "..."}]
  • Google Gemini SDK contents: [{"role": "user", "parts": [{"text": "..."}]}]
  • LiteLLM / Azure OpenAI / Ollama / vLLM message arrays
  • pandas DataFrames, polars DataFrames / LazyFrames
  • list[dict], list[dspy.Example], single dspy.Example

configure(lm=None, dataset_lm=None, sub_lm=None)

Configures the models used during signature generation.

Parameter Type Description
lm dspy.LM | None Default RLM model. Falls back to the model configured through dspy.configure
dataset_lm dspy.LM | None Optional RLM model override for dataset sources
sub_lm dspy.LM | None Optional model used for recursive sub-queries

(back to top)

Contributing

Quick workflow:

  1. Fork and branch: git checkout -b feature/name
  2. Make changes
  3. Commit and push
  4. Open a Pull Request

(back to top)

License

MIT (as declared in pyproject.toml).


Built by thememium

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dspy_auto_signature-0.1.1.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dspy_auto_signature-0.1.1-py3-none-any.whl (35.5 kB view details)

Uploaded Python 3

File details

Details for the file dspy_auto_signature-0.1.1.tar.gz.

File metadata

  • Download URL: dspy_auto_signature-0.1.1.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dspy_auto_signature-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d3f42358a9bc266993d34f40e7fd355e303a487f2872b257e2d01a79eb3a31a0
MD5 1e2e44a2a2cbe804c20e8189db215c73
BLAKE2b-256 7254897eb0e3801c5b7188500ba36e090a9406fafdaf5e2c53a55da7e2cc1631

See more details on using hashes here.

File details

Details for the file dspy_auto_signature-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dspy_auto_signature-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 35.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dspy_auto_signature-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3613c92a3a9c9c7efc8957b16d4d3fa223f53c834021d35e0fba949ca1623ee5
MD5 1764c2269dad7c40993c6a6dbb357366
BLAKE2b-256 f042525c407b834cfb951d420c66242cb213673983f37a5c7acba4e43c4f2330

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page