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.

Build with less context

Put compression in front of your next LLM call.

Use the hosted API or run SuperCompress locally. Keep the evidence, drop the token waste, and measure the savings before it reaches your model.

Get an API keyRead the guide