Skip to content

JSON Schema potential doesn't handle unions of integer and number correctly #111

@DRMacIver

Description

@DRMacIver

The following schema:

from genlm.control.potential.built_in.json import JsonSchema

potential =  JsonSchema({
      "type": "array",
      "items": {"anyOf": [{"type": "integer"}, {"type": "number"}]},
 })

print(await potential.complete(b'[0.0]'))

This prints -inf. It should print 0.0.

The underlying problem is that our fail fast parser is not handling the union correctly. It's parsing the first element as 0, then erroring when it sees a . rather than a , after it. We need to add some lookahead to the integer parser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions