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.
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.
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.