Advanced guide

Structured output compression

LLMs increasingly return structured data (JSON, XML, function calls). SuperCompress preserves the information needed for accurate structured outputs while reducing input tokens.

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

Why structured outputs need care

When an LLM returns JSON, every field in the JSON depends on some part of the input context. Removing the wrong line can cause incorrect field values. SuperCompress's query-aware selection ensures that lines containing data for the output fields are preserved.

JSON mode with compression

from supercompress import Compressor
comp = Compressor()

def extract_structured(context, schema_description):
    # Compress against the schema requirements
    result = comp.compress(context, schema_description)
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {"role": "system", "content": f"Extract data in JSON format. {schema_description}"},
            {"role": "user", "content": result.compressed_text},
        ],
        response_format={"type": "json_object"}
    )
    return json.loads(response.choices[0].message.content)

Frequently asked questions

Does compression affect JSON output quality?

No. When compressed against the schema description, the lines needed for each JSON field are preserved.

Does it work with function calling?

Yes. Compress against the function description and parameter schema.

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