Framework integration

DSPy compression integration

DSPy optimizes LLM prompts automatically. SuperCompress adds a compression layer that reduces token costs before DSPy's prompts reach the model.

By Arjun Shah - Creator of SuperCompress - Updated 2026-07-03

DSPy integration

import dspy
from supercompress import Compressor

comp = Compressor()

class CompressedModule(dspy.Module):
    def __init__(self, signature):
        super().__init__()
        self.signature = signature

    def forward(self, **kwargs):
        # Compress long context inputs before DSPy processes them
        for key, val in kwargs.items():
            if isinstance(val, str) and len(val) > 1000:
                kwargs[key] = comp.compress(val, str(self.signature)).compressed_text
        return super().forward(**kwargs)

Frequently asked questions

Does compression affect DSPy optimization?

No. DSPy optimizes the prompt structure, not the input context. Compression only reduces input size.

Can I use it with DSPy's teleprompters?

Yes. Compression works before the teleprompter's optimized prompt is assembled.

Try it yourself

Paste your long prompt into the playground, ask a question, and see what SuperCompress keeps and removes. Free, no signup needed.

Open the Playground Embed the badge