How to Effectively Reduce Token Consumption in the LLM Era
Token consumption directly affects cost, latency, and context window utilization in production LLM applications. This article explains why JSON wastes tokens when injecting structured data into prompts, introduces a token-optimized tabular serialization approach for uniform object arrays, examines its built-in validation guardrails, defines where it applies and where it does not, and presents a systematic engineering strategy for reducing token usage across inputs, prompts, outputs, and architecture.
How to Effectively Reduce Token Consumption in the LLM Era
1. Why Token Consumption Has Become a Core Problem
As LLM applications move into production, token cost has become an unavoidable engineering concern. Whether you call a commercial model API or run a self-hosted inference service, the number of input and output tokens directly affects cost, latency, and context window utilization. When building applications such as RAG (retrieval-augmented generation), intelligent customer service, or data analysis assistants, teams often need to inject large amounts of structured data into the model—user profiles, order records, log entries, configuration tables—and the most common way to express this data is JSON.
The problem is that JSON was designed for machine-to-machine data exchange, not for LLM token metering. JSON is full of characters that are “wasted” from the model’s perspective: every field repeats its key name, along with braces, brackets, quotes, and colons. When an array contains hundreds or thousands of structurally identical records, the key names are repeated hundreds or thousands of times. All of this repetition is tokenized and billed, yet it adds almost nothing to the model’s understanding of the data. Compressing structured input without losing semantic content has therefore become an important topic in prompt engineering.
2. A Token-Oriented Structured Representation Format
To address this pain point, a class of “token-optimized structured markup formats” has emerged in the industry. Its positioning needs to be clarified first: it is not meant to replace JSON for data exchange between programs, but to serve as an intermediate/prompt-layer format between the backend and the model. Internal data storage and API transport still use standard JSON; only when data is actually about to be sent to the LLM is it converted into this compact format, thereby reducing cost and improving context utilization.
2.1 Core Idea: Treat Arrays as Tables
The key innovation of this type of format is re-expressing a “uniform array of objects” as a table. Take a typical user list as an example. In JSON it looks like this:
{"users": [{ "id": 1, "name": "Alice", "role": "admin" },{ "id": 2, "name": "Bob", "role": "user" }]}
Even in YAML, the key names must be repeated for every record:
users:- id: 1name: Alicerole: admin- id: 2name: Bobrole: user
The tabular representation looks something like this:
users[2]{id,name,role}:1,Alice,admin2,Bob,user
The header line carries three pieces of information: users is the key name, [2] declares the array length (2 rows), and {id,name,role} declares the columns of this “table.” Each subsequent line is one record, with fields separated by commas. Notice that no matter how many rows the array has, the key names appear only once, and braces and quotes almost entirely disappear. The larger the array and the more uniform the records, the more significant the compression.
2.2 How Significant Is the Compression?
According to publicly available comparison experiments for this type of format, benchmarking several common serialization approaches on the same dataset yields roughly the following results: the tabular compact format expresses the data in about 2,700+ tokens, and its data comprehension accuracy (around 73%) is actually the highest among the formats tested. Minified single-line JSON requires about 3,000 tokens, YAML about 3,700, pretty-printed JSON about 4,500, and XML over 5,000.
This comparison reveals two important conclusions. First, for large-scale, structurally uniform object arrays, a tabular format typically saves 30% to 60% of tokens compared to formatted JSON. Second, fewer tokens does not mean the model understands the data worse—reducing redundant symbols actually lowers interference, and the regular tabular structure closely resembles the tabular text the model saw extensively in its training corpus, so comprehension accuracy improves rather than degrades.
3. Built-in “Guardrails”: Helping the Model Self-Validate
This type of format has another easily overlooked but highly practical design: it explicitly carries constraint information in its syntax. For example, the array length declaration [2] is a natural validation anchor—if the model needs to generate or restate the structure, it can check whether the row count matches the declaration. The column declaration constrains the field set of each record, reducing the risk of missing fields or hallucinated additions.
The essence of this “guardrails” approach is to encode constraints—which would otherwise have to be described in prompt text (“make sure to output N records,” “each record must contain the following fields”)—directly into the data format itself. This saves prompt tokens and makes the constraints programmatically verifiable: when the parser finds that the row count does not match the declaration, it can raise an error or trigger a retry, improving output stability.
4. Applicable Scenarios and Boundaries
Like any technical solution, this type of compact format has its boundaries:
Applicable scenarios:
- Large-scale object arrays with consistent fields, such as database query results, report data, and structured items retrieved in search;
- RAG scenarios where multiple homogeneous document fragments need to be injected;
- Tasks where the model reads structured data and must produce structured output—the model can be asked to return results in the same format, saving tokens in both directions.
Scenarios where it does not apply or offers limited benefit:
- Deeply nested, highly irregular data with varying fields. In such cases key-name repetition is already minimal, so compression gains are low, and forced flattening harms readability;
- Data exchange and persistence between programs. JSON’s ecosystem (validation, parsing, tooling) is far more mature; the compact format should only exist in the “last mile” before data is sent to the model;
- Small data volumes where token usage is not a concern, since the conversion overhead may outweigh the benefit.
5. A Holistic Engineering Strategy
Reducing token consumption should not rely on a single format—it requires a combination of measures:
- Input side: Filter out irrelevant fields and only send the columns the model actually needs; summarize or truncate long texts; use tabular compact representations for homogeneous arrays.
- Prompt side: Streamline system prompts and avoid repeated instructions; encode constraints into format declarations rather than natural-language descriptions.
- Output side: Explicitly limit output length and structure, and require the model to return only what is needed, avoiding verbose self-restatement.
- Architecture side: Use caching to reuse unchanged context prefixes; apply rolling summaries to conversation history; break large tasks into smaller ones instead of stuffing all data in at once.
- Measurement side: Establish dual monitoring of token consumption and model accuracy. The goal of compression is never simply to save money, but to strike a balance among cost, latency, and effectiveness—as the comparison experiment above shows, a well-designed compact format can optimize all three at once.
6. Conclusion
Competition among LLM applications is, to some extent, competition in context utilization efficiency. Through the simple transformation of “array tabularization,” token-optimized structured representation formats significantly reduce token usage while maintaining or even improving the model’s comprehension accuracy; their built-in length and field declarations also provide natural anchors for output validation. By using such a format as the prompt layer between backend JSON and the model—combined with systematic measures like input filtering, output constraints, and context caching—developers can make every token count without sacrificing results.
