← Back to michaelbastos.com
YAML Matters in the Age of LLMs

YAML Matters in the Age of LLMs

7 min read
YAMLLLMsDeveloper ToolsTokenizationCost Optimization

LLMs favor YAML's lean token footprint, keeping the format relevant, and cost-effective despite developer gripes.

Published on

The love‑hate relationship with YAML

For two decades developers have joked that "YAML ain't markup language, it's yet another meddlesome language." Indentation errors, mysterious type coercion, and whitespace‑driven syntax have spawned countless memes. Many teams migrated configuration files to JSON, TOML, or even XML just to avoid the pitfalls.

Yet YAML refuses to die. Kubernetes manifests, GitHub Actions, Ansible playbooks, and nearly every modern CI/CD pipeline rely on it. The latest twist? Large language models (LLMs) give YAML a brand‑new advantage.

Why token count suddenly matters

LLMs are priced and throttled by tokens, the sub‑word pieces a model consumes and emits. Fewer tokens mean faster inference and lower cost. Formats that convey the same information with fewer characters win immediate economic points.

YAML is naturally concise:

  • Keys don't need quotes unless special characters appear.
  • Arrays use a leading dash instead of brackets and commas.
  • The lack of curly braces and trailing commas trims dozens of characters in large documents.

Small differences add up when prompts include multi‑kilobyte configs or when an agent exchanges YAML back and forth over hundreds of iterations.

YAML vs JSON vs TOML: a byte‑level look

Below is an example profile in YAML and JSON. Count the non‑whitespace characters.

name: Ada Lovelace
age: 36
languages:
  - Analytical Engine
  - Fortran
{
  "name": "Ada Lovelace",
  "age": 36,
  "languages": ["Analytical Engine", "Fortran"]
}

The YAML version weighs in at 73 bytes; JSON hits 99 bytes, a 26 % bump. Tokenizers aren't one‑byte‑per‑token, but character savings and the absence of quotes translate into fewer tokens almost one‑for‑one for ASCII‑only text.

Cost savings in practice

Imagine a prompt chain that embeds a 5 KB YAML snippet on every request. If that config appears 10 000 times a day:

  • YAML: ~5 MB → ~375 000 tokens → $0.75/day at $0.002 per 1 K tokens.
  • JSON: ~6.3 MB → ~470 000 tokens → $0.94/day.

That $0.19 delta may look trivial until you scale to millions of daily calls or keep the context window open persistently for autonomous agents. Multiply by 30 days and suddenly your "annoying" syntax is saving thousands of dollars.

Where YAML still falls short?

Conciseness isn't everything. Choose JSON or protobuf when you need strict schemas, strong typing, or streaming parsers. YAML's flexible scalar rules can misinterpret on, yes, or dates. In security‑sensitive code paths, explicit is safer than implicit.

Writing LLM‑friendly YAML

  1. Stick to strings: Quote values that could be mis‑typed ("on", "03").
  2. Flatten deeply nested data: LLMs handle flat key paths more reliably.
  3. Keep comments minimal: Some tokenizers count them; strip before sending to production models.
  4. Validate with yamllint: Catch indentation quirks early.

Developers may never fall in love with YAML's whitespace quirks, but the economics of token‑based AI are hard to ignore. As long as LLMs dominate software workflows and pricing remains token‑centric then YAML's smaller footprint grants it a second life. Hate it if you must, but YAML is poised to outlast the joke memes and remain a first‑class citizen in the AI era.