Skip to main content

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 inspects a prompt or dataset and generates a complete dspy.Signature subclass. Structured inputs are designed deterministically; structureless prompts get a single LLM call (dspy.ChainOfThought) by default, with the heavier dspy.RLM architect available via mode="rlm".

  • 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+ and DSPy 3.2+. Deno is only needed for mode="rlm" (sandboxed execution); the other modes never run generated code.

(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 LLM architect 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
mode "auto" | "fast" | "cot" | "rlm" Generation strategy. Defaults to auto — see below

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

Generation modes (mode parameter):

Mode Behavior
auto Deterministic structural design first; falls back to a single dspy.ChainOfThought call for structureless prompts
fast Fully deterministic — never contacts an LLM for signature design
cot LLM-driven middle tier: a single dspy.ChainOfThought call designs the signature. No Deno sandbox or recursive loop
rlm Full dspy.RLM architect: sandboxed exploration with recursive sub-queries. Slowest, but richest signatures

Use cot when you want the LLM architect on structured inputs too, and rlm when you want maximum quality on complex prompts (requires Deno).

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

Configures the models used during signature generation.

Parameter Type Description
lm dspy.LM | None Default generation model. Falls back to the model configured through dspy.configure
dataset_lm dspy.LM | None Optional generation model override for dataset sources
sub_lm dspy.LM | None Optional cheap inner model used by mode="rlm" 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

Metadata

Release files for dspy-auto-signature 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dspy-auto-signature 0.1.5
File Size Uploaded
dspy_auto_signature-0.1.5.tar.gz 31.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dspy-auto-signature 0.1.5
File Interpreter ABI Platform
dspy_auto_signature-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 71.9 kB

Release files / dspy_auto_signature-0.1.5.tar.gz

Download URL dspy_auto_signature-0.1.5.tar.gz
Size 31.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0381053321667260c01d46bf9d2cb4132d432cf5cb3a12e1d994698461eb72ac
BLAKE2b-256 checksum
How to use checksums
db306a0cb17244e713bf29bf0ec1b8f4acf4011516e5af6a17f548d460925450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / dspy_auto_signature-0.1.5-py3-none-any.whl

Download URL dspy_auto_signature-0.1.5-py3-none-any.whl
Size 40.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32a207ed8e08e140e44e848b067e89a7c22b46d38f6a143ee99be7346dcf1426
BLAKE2b-256 checksum
How to use checksums
57d2957a072006704390eb13f4f4a2c4309716eb70c0066444c21643c876342d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.13 {"installer":{"name":"uv","version":"0.12.13","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page