Skip to content

[FEAT]: Introduce TOON Encoding for Token Optimization in AI Assistant #456

Closed
Vatsal-Verma wants to merge 5 commits intoaccordproject:mainfrom
Vatsal-Verma:vatsal/444/introducing-toon
Closed

[FEAT]: Introduce TOON Encoding for Token Optimization in AI Assistant #456
Vatsal-Verma wants to merge 5 commits intoaccordproject:mainfrom
Vatsal-Verma:vatsal/444/introducing-toon

Conversation

@Vatsal-Verma
Copy link
Copy Markdown
Contributor

Problem

The AI Assistant in Template Playground currently injects raw JSON agreement data into prompts when assisting users with TemplateMark, Concerto models, or explanations.
For medium-to-large agreements, this leads to:

  • High token consumption
  • Increased latency and cost

Key Features:

  • 📊 Token-Efficient & Accurate: TOON reaches 74% accuracy (vs JSON's 70%) while using ~40% fewer tokens.
Image
TOON           ████████████████████   26.9 acc%/1K tok  │  73.9% acc  │  2,744 tokens
JSON compact   █████████████████░░░   22.9 acc%/1K tok  │  70.7% acc  │  3,081 tokens
YAML           ██████████████░░░░░░   18.6 acc%/1K tok  │  69.0% acc  │  3,719 tokens
JSON           ███████████░░░░░░░░░   15.3 acc%/1K tok  │  69.7% acc  │  4,545 tokens
XML            ██████████░░░░░░░░░░   13.0 acc%/1K tok  │  67.1% acc  │  5,167 tokens

how this works

1 → User Input
TemplateMark, Concerto, and JSON data from the Playground editors

2 → TOON Encoding
JSON agreement data is encoded into TOON for token optimization

3 → API Request
TOON-encoded context is sent to the AI via a standard JSON API call

4 → AI Processing
The model uses TOON only as internal context

5 → AI Response
Normal JSON response with generated code or suggestions

6 → User Output
Results shown in standard editor formats (no TOON exposure)

Sample format

JSON

{
  "user": {
    "id": 123,
    "name": "Alice Johnson",
    "email": "alice@example.com",
    "profile": {
      "age": 28,
      "city": "San Francisco",
      "interests": [
        "coding",
        "music",
        "travel"
      ]
    },
    "orders": [
      {
        "id": "ORD-001",
        "item": "Laptop",
        "price": 1299.99,
        "status": "delivered"
      },
      {
        "id": "ORD-002",
        "item": "Headphones",
        "price": 199.99,
        "status": "shipped"
      },
      {
        "id": "ORD-003",
        "item": "Mouse",
        "price": 49.99,
        "status": "processing"
      }
    ]
  }
}

TOON Format:

user:
  id: 123
  name: Alice Johnson
  email: alice@example.com
  profile:
    age: 28
    city: San Francisco
    interests[3]: coding,music,travel
  orders[3]{id,item,price,status}:
    ORD-001,Laptop,1299.99,delivered
    ORD-002,Headphones,199.99,shipped
    ORD-003,Mouse,49.99,processing

Reference

https://github.com/toon-format/toon

Result

  • Using TOON internally optimizes AI Assistant performance while keeping the user experience and data formats unchanged.
Note: here we are not altering any data, we are just encoding the json --> TOON before feeding to API, and response will be in JSON. 

handling pr #446

Signed-off-by: Vatsal-Verma <lastav1234@gmail.com>
@Vatsal-Verma Vatsal-Verma requested a review from a team as a code owner December 25, 2025 09:38
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 25, 2025

Deploy Preview for ap-template-playground ready!

Name Link
🔨 Latest commit a74ec77
🔍 Latest deploy log https://app.netlify.com/projects/ap-template-playground/deploys/69d17829adab8d0008b19f05
😎 Deploy Preview https://deploy-preview-456--ap-template-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Signed-off-by: Vatsal-Verma <lastav1234@gmail.com>
@Vatsal-Verma
Copy link
Copy Markdown
Contributor Author

Vatsal-Verma commented Dec 25, 2025

I tested this PR with and without TOON enabled. The results show a consistent reduction in token usage while producing equivalent responses. This confirms that TOON provides a positive impact on token efficiency for the current prompt sizes, with larger gains expected for more structured and repetitive inputs.

test2 test1

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Jan 13, 2026
@github-actions github-actions bot removed the Stale label Jan 25, 2026
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Feb 11, 2026
@github-actions github-actions bot removed the Stale label Feb 16, 2026
@Vatsal-Verma Vatsal-Verma deleted the vatsal/444/introducing-toon branch April 16, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant