TOON Converter for Langflow
A custom Langflow component that converts structured data (JSON, XML, CSV, HTML) into TOON (Token-Oriented Object Notation) format to optimize token usage for LLM prompts.
Features
- Multi-format Support: Convert JSON, XML, CSV, and HTML to TOON format
- Token Optimization: Achieve 30%+ token reduction compared to formatted JSON
- Configurable Delimiters: Choose between comma, tab, or pipe separators
- Token Statistics: View before/after token counts and savings percentage
- Memory Warnings: Get alerts for large datasets before processing
- Detailed Error Messages: Get location-specific error messages with corrected examples
Installation
From Source
git clone https://github.com/faisolp/langflow-toon-component.git
cd langflow-toon-component
pip install -e .
Dependencies
pip install -r requirements.txt
Required packages:
tiktoken>=0.5.0- Token counting for optimization analysisxmltodict>=0.13.0- XML parsing and conversionpytest>=7.0.0- Testing framework (development only)pytest-cov>=4.0.0- Test coverage reporting (development only)
Usage
Python API Usage
from langflow_toon import ToonConverter
from langflow_toon.models.data import ConversionConfig, Delimiter
# Initialize converter
converter = ToonConverter()
# Convert JSON to TOON
json_data = '{"users": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]}'
result = converter.convert(json_data, input_format='JSON')
print(result.toon_output)
# Output:
# users[2]{id,name}:
# 1,Alice
# 2,Bob
print(f"Token reduction: {result.token_reduction} ({result.token_reduction/result.original_tokens*100:.1f}%)")
Basic Usage in Langflow
- Add the "TOON Converter" component to your Langflow flow
- Connect your data source to the
input_textport - Configure the
input_format(or enableauto_detectfor automatic detection) - Choose your preferred
csv_delimiter(comma, tab, or pipe) - Toggle
sort_keysto alphabetically sort object keys - Toggle
ensure_asciito encode non-ASCII characters - Connect the
toon_outputto your LLM prompt - View
original_tokens,toon_tokens, andtoken_reductionstatistics
Example: JSON to TOON
Input (JSON):
{
"users": [
{"id": 1, "name": "Alice", "role": "admin"},
{"id": 2, "name": "Bob", "role": "user"}
]
}
Output (TOON):
users[2]{id,name,role}:
1,Alice,admin
2,Bob,user
Token Savings: 85 → 42 tokens (50.6% reduction)
Example: CSV with Tab Delimiter
Input (CSV):
name,age,city
Alice,30,NYC
Bob,25,LA
Output (TOON with tab delimiter):
data[2 ]{name age city}:
Alice 30 NYC
Bob 25 LA
Example: Complete Langflow Workflow
[HTTP Request] → [TOON Converter] → [LLM Prompt]
↓
[Token Stats Display]
Flow Configuration:
- HTTP Request: Fetch JSON data from an API
- TOON Converter:
input_text: Connect from HTTP Request outputinput_format: JSONcsv_delimiter: comma (default)auto_detect: false (format known)sort_keys: false (preserve order)ensure_ascii: false (keep Unicode)
- LLM Prompt: Use
{{toon_output}}variable in prompt template - Token Stats Display: Show
{{original_tokens}},{{toon_tokens}},{{token_reduction}}
Example: Multi-Format Processing Pipeline
┌─────────────┐
│ Format │
│ Detector │
└──────┬──────┘
│
┌────────────────┼────────────────┐
│ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼────┐
│ JSON │ │ XML │ │ CSV │
│ Source │ │ Source │ │ Source │
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
└───────────────┼───────────────┘
│
┌──────▼──────┐
│ TOON │
│ Converter │
└──────┬──────┘
│
┌──────▼──────┐
│ LLM │
│ Processing │
└─────────────┘
Component API
Inputs
| Port | Type | Description |
|---|---|---|
input_data |
string | Raw data to convert (JSON, XML, CSV, or HTML) |
input_format |
enum | Data format: AUTO, JSON, XML, CSV, HTML |
delimiter |
enum | TOON field delimiter: COMMA, TAB, PIPE |
sort_keys |
boolean | Sort object keys alphabetically (default: false) |
Outputs
| Port | Type | Description |
|---|---|---|
toon_output |
string | TOON formatted data |
token_stats |
object | Token usage statistics |
error |
string | Error message (if conversion fails) |
Development
Running Tests
# Run all tests
pytest tests/
# Run unit tests only
pytest tests/unit/
# Run with coverage
pytest --cov=langflow_toon tests/
Project Structure
langflow_toon/
├── __init__.py
├── component.py # Main Langflow custom component
├── converters/ # Format-specific converters
├── validators/ # Input and TOON validation
├── utils/ # Token counting, memory estimation, error formatting
└── config/ # Constants and configuration
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Links
Metadata
Release files for langflow-toon 0.1.51
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langflow_toon-0.1.51.tar.gz | 22.8 kB | Without provenance | Details for langflow_toon-0.1.51.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langflow_toon-0.1.51-py3-none-any.whl | Python 3 | none | any | Details for langflow_toon-0.1.51-py3-none-any.whl |
Total release size: 51.9 kB
Release files / langflow_toon-0.1.51.tar.gz
| Download URL | langflow_toon-0.1.51.tar.gz |
|---|---|
| Size | 22.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d86e2a56050a2d29cb52b333dcf10e787c824f69dd22c86c226b90dd7716664b
|
|
BLAKE2b-256 checksum How to use checksums |
957ee7e51cf212eec33ad8433935666814ad887228c87db0c811e3edfff7a253
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / langflow_toon-0.1.51-py3-none-any.whl
| Download URL | langflow_toon-0.1.51-py3-none-any.whl |
|---|---|
| Size | 29.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12093d531cf316c760880e47ed1cdeab52398cfe60a2e96da2f2dd1262aba656
|
|
BLAKE2b-256 checksum How to use checksums |
d17f3936a802b9b538be3d94b7822f073e2afa58c94c45a827ea9f83b6743bb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for langflow-toon 0.1.51
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.