helgesverre/toon
TOON is a compact, human-readable data format that cuts token usage when sending structured data to LLMs. This PHP port offers simple encode and decode methods, works on PHP 8.1+, and supports arrays, objects, and primitives.
Architecture fit. TOON is a stateless serialization library, not a framework component. It exposes a static surface (Toon::encode(), Toon::decode(), validation, config options) with no service provider, facade, config-publish step, or container bindings. That makes it a natural fit as an edge dependency in the LLM data path — prompt assembly, agent tool-result payloads, RAG context packing, structured-output parsing — rather than as a core platform component. The value proposition is directly measurable (token reduction → cost and latency per LLM call, plus context-window headroom), which is rare for a library of this size. It is not a fit for persistence, API wire formats, caching keys, or anything that must be interoperable with non-LLM consumers; those must stay JSON.
Integration feasibility. Very high. composer require helgesverre/toon, PHP 8.1+, MIT, no transitive dependencies implied, no infrastructure. A single engineer can wrap it in a ContextSerializer-style interface behind our own abstraction in under a day, and the abstraction is the actual deliverable — it decouples product code from the format choice in case TOON loses to a competing representation.
Technical risk. Concentrated in three areas:
null vs empty string, empty array vs empty object, strings containing : or newlines requiring escaping, unicode. Any path that decodes model output back into application data is a trust boundary and needs strict validation plus failure handling.Key questions for the maintainer / spike.
Stack fit. Clean. Requires PHP 8.1+, satisfied by Laravel 10/11/12 baseline. No queue, cache, filesystem, or database surface. Works identically in HTTP, queue worker, and CLI contexts, which matters because LLM jobs frequently move between them.
Migration path. TOON is additive, not substitutive. Do not replace any existing JSON contract. Introduce it as an alternate codec on the outbound prompt payload and the inbound structured-response path only, gated per feature flag and per model. Existing JSON-based integrations remain the default until a feature proves a win.
Compatibility. Two axes to verify in the spike: (a) PHP/Laravel version matrix — trivial; (b) model matrix — non-trivial, and the real gate. Pair every encoding change with a golden-file regression suite so that a library upgrade can't silently alter model inputs.
Sequencing.
ContextSerializer interface and a JSON implementation, then a TOON implementation behind it.Maintenance. Low and predictable. No runtime services, no schema migrations, no scheduled tasks. Cost is concentrated in pinning: a composer.lock constraint plus golden-file tests, and a standing check that the upstream spec version and the PHP port haven't diverged. Budget a few hours per quarter, more if the format gains adoption and churns.
Support. No commercial support; GitHub issues only, single maintainer, no SLA. Acceptable given the small surface and MIT license — the realistic fallback is a vendored fork. Support burden will actually land on our own platform team, because the failure mode we'll field is "the model returned something we couldn't decode," not "the library is broken."
Scaling. Negligible on our side: pure CPU, in-process, linear in payload size, no allocation concerns at typical prompt sizes. The interesting scaling property is economic and favourable — token savings compound linearly with LLM call volume, so the ROI improves as adoption grows. Watch payload memory on very large context assemblies (multi-MB RAG bundles) and consider streaming or chunking if those appear.
Failure modes to instrument.
Ramp-up. Hours, not days. Static API, clear README, quick-start examples, changelog and releases present. The engineering time is not in learning the library — it is in building the eval harness and the serializer abstraction, and that work is transferable regardless of whether TOON survives.
How can I help you explore Laravel packages today?