Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Toon Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Token-Oriented Object Notation - A compact data format for reducing token consumption when sending structured data to LLMs (PHP implementation)

Frequently asked questions about Toon
What is TOON and why would I use it in a Laravel application?
TOON (Token-Oriented Object Notation) is a compact, human-readable format for structured data sent to LLMs. In Laravel, use it as an alternate codec when assembling prompts, packing RAG context, or parsing structured model responses to reduce token usage. It is not a replacement for JSON in APIs, persistence, or caching.
How do I install helgesverre/toon?
Run composer require helgesverre/toon. The package requires PHP 8.1 or higher and has a static API, so there is no service provider, facade, or config-publish step. You call Toon::encode() and Toon::decode() directly.
Does helgesverre/toon support Laravel 10, 11, and 12?
Yes in practice, because the package is framework-agnostic and only requires PHP 8.1+. Laravel 10, 11, and 12 all satisfy that PHP baseline, so Laravel version compatibility is mostly a PHP matrix check. It has no queue, cache, database, or filesystem integration to conflict with framework versions.
Do I need to register a service provider or publish config for helgesverre/toon?
No. The library is stateless and exposes Toon::encode(), Toon::decode(), validation, and config options without container bindings or a Laravel service provider. Configuration is handled through the package's static API rather than a publishable Laravel config file. Wrap it behind your own serializer interface if you want product code decoupled from the format.
How much token reduction does TOON provide compared with JSON?
TOON is designed to cut token consumption for structured LLM payloads, especially arrays of uniform records, but savings depend heavily on payload shape. Do not assume a fixed percentage: measure your real prompts with the tokenizer used by your model. Treat average and worst-case reduction as something to validate in a spike rather than a package guarantee.
Can Toon::decode round-trip PHP arrays without losing types?
Not reliably for every PHP value. Round-tripping can blur numeric-looking strings, floats and precision, null versus empty string, empty arrays versus empty objects, and strings containing separators or newlines. Any path that decodes model output back into application data is a trust boundary, so validate strictly and cover edge cases with tests.
How should I test whether an LLM understands TOON in my Laravel app?
Test model comprehension separately from PHP correctness, because the library can round-trip perfectly while the model misreads the payload. Build a small eval harness using your real payload shapes, feature-flag TOON per model, and compare accuracy, latency, and token counts against JSON. Keep golden-file regression tests so library upgrades cannot silently change model inputs.
How do I handle malformed TOON or validate decoded data?
The package exposes a validation surface, but before production you should confirm its exception hierarchy, behavior on malformed input, and whether decode-side schema validation hooks meet your needs. In application code, wrap Toon::decode() in try/catch and run your own schema validation before trusting model output. Fail closed rather than relying on silent coercion.
Can I use TOON instead of JSON for APIs or cache keys?
No. TOON is intended only for the LLM data path, such as prompt assembly, tool-result payloads, RAG context packing, and structured-output parsing. Persistence, public API wire formats, cache keys, and anything consumed by non-LLM systems should stay JSON. Introduce TOON as an additive, feature-flagged codec rather than replacing existing JSON contracts.
Is helgesverre/toon actively maintained and safe as a long-term dependency?
It is a small, effectively single-maintainer project with limited stars and dependents, and the TOON spec is young, so treat it as a measured bet rather than a durable vendor commitment. The encoding and decoding surface is small and the spec is public, so a fork or reimplementation is a low-cost contingency. Pin versions and keep regression tests around your encoded payloads.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator