Menu

1 / 2

Cutting 35-60% of LLM Structured Output Tokens at the Wire Level in Pure Go

DEV Community: go·Javier García Camacho·15 days ago
#Peewk9Kx
#devtogo#devto#dev#schema#json
Long article (503 words) — no AI summary yet.
Reading 0:00
15s threshold

When you ask an LLM for structured JSON (via OpenAI response_format json_schema , OpenAI tools[] , or Anthropic tools[].input_schema ), you pay an invisible output token tax on every single record.

Ask for 40 invoice line items with 7 fields, and the model repeats those 7 JSON key names 40 times. That is 280 key emissions spent on metadata the receiver already knows from the schema.

As a Technical Integrations Specialist working with REST APIs and webhooks, I wanted to fix this at the wire level—so an application can change a single environment variable ( OPENAI_BASE_URL or ANTHROPIC_BASE_URL ) without rewriting prompts or application models.

That became wiretuple (MIT, Go 1.23, zero external dependencies).

The lossless positional bijection

Given a deterministic key ordering ( required fields in schema order, followed by remaining properties sorted lexicographically), an array of objects:

[ { "line_identifier" : "li_0000" , "product_sku" : "SKU-00000" , "quantity_units" : 1 } , { "line_identifier" :…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.