Skip to main content
All engineering notes
Systems & Architecture 7 min read Yashvardhan Thanvi July 15, 2026

AST Syntax-Aware Normalization for JSON, XML, and YAML Prompts

Compressing Structural Data Payloads Without Invocation Failures

Mathematical intuition
Parses structured inputs into AST node trees, normalizes formatting whitespace, and prunes low-entropy array elements while validating schema structure.
Key takeaways
  1. Compressing JSON or XML via raw text token truncation causes syntax errors and parse failures.
  2. LLMSlim format optimizers validate AST integrity before and after structural reduction.
  3. Safely compresses large JSON API payloads passed into function-calling LLMs.

1. Structural JSON Compression Pattern

Using format-specific modes in LLMSlim:

json_opt_example.pypython
from llmslim import compress

json_prompt = """{
  "request_id": "req_99281a",
  "instructions": "Extract entities from payload",
  "schema": {
    "type": "object",
    "properties": {
      "user_name": {"type": "string"},
      "user_id": {"type": "integer"}
    }
  }
}"""

# Perform AST syntax-aware normalization and compression
result = compress(json_prompt, mode="json", target_ratio=0.5)

print(f"Original Tokens: {result.original_tokens}")
print(f"Compressed Tokens: {result.compressed_tokens}")
print(result.compressed_text)