spring-ai
spring-ai copied to clipboard
Add TOON (Token-Oriented Object Notation) Support
trafficstars
Expected Behavior
Spring AI should support the TOON format as a serialization option when sending structured data to LLM models.
Example usage:
ExampleObject exampleObject = new ExampleObject();
String response = chatClient.prompt()
.mapper(toonMapper) // <-- the TOON mapper bean
.user(exampleObject)
.call()
.content();
This would allow applications to use TOON instead of JSON/YAML for model inputs, improving efficiency and reducing token count.
Current Behavior
Spring AI currently supports JSON and YAML (via built-in or user-provided serializers), but there’s no native TOON support. Developers must manually serialize/deserialize TOON data and integrate it into prompts or function-calling logic.
Context
- TOON (Token-Oriented Object Notation) is a compact, token-efficient format designed for LLM input/output.
- Article reference:
- https://codefarm0.medium.com/toon-a-token-friendly-data-format-for-the-llm-era-with-java-code-examples-4dcafbfb03ce
- https://blog.arun.im/toon4j-slash-your-llm-token-costs-by-50-with-this-java-library-1e16578ff9eb
- Benefits of adding TOON support:
- Reduces token usage and improves prompt window efficiency.
- Provides native serialization/deserialization similar to JSON/YAML.
- Makes it easier to handle structured POJO exchanges with LLMs.
- Workarounds exist (manual TOON serialization), but a built-in module would provide first-class support aligned with Spring AI’s extensibility model.