Skip to content

Empty arrays (eg matches[0]:) are often misinterpreted by LLMs #19

@bradvogel

Description

@bradvogel

Issue Type

Other specification error

Description

This isn’t a bug in the spec, more a data point about how LLMs interpret empty arrays in TOON. For possible consideration in future iterations of this spec.

When encoding empty arrays, TOON produces:

$ npm ls @toon-format/toon
project0.0.1 /Users/dev
└── @toon-format/[email protected] -> ./../../node_modules/.pnpm/@[email protected]/node_modules/@toon-format/toon
$ node
> const { encode } = require('@toon-format/toon');
> console.log(encode({ log: { matches: [] } }))
log:
  matches[0]:

When I ask LLMs "were there any matches?", most respond with something like "yes (though it looks undefined / empty)". They seem to treat matches[0] as an array with a empty element at index 0.

Since TOON is explicitly designed as an LLM-friendly text format, this might be useful to re-consider.

Specification Reference

Array header syntax

Current Behavior

see above

Expected Behavior

n/a - this isn't a bug

Example

Impact

Devs need to work around this, eg

  • giving LLM instructions on how to interpret TOON syntax
  • replacing empty arrays with more explicit language like:
> console.log(encode({ log: {matches: 'none'}}))
log:
  matches: none

Proposed Fix

No response

Additional Context

No response

Checklist

  • I have searched for similar issues in the issue tracker
  • I have checked the latest version of the specification
  • This issue is about the specification itself (not implementation bugs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions