noamgat / lm-format-enforcer

Enforce the output format (JSON Schema, Regex etc) of a language model
MIT License
1.42k stars 65 forks source link

Supporting of Tuple validation #50

Closed Chen0x00 closed 9 months ago

Chen0x00 commented 9 months ago

The validation definition for a tuple is as follows (items is array):

{
  "type": "array",
  "items": [
    { "type": "number" },
    { "type": "string" },
    { "enum": ["Street", "Avenue", "Boulevard"] },
    { "enum": ["NW", "NE", "SW", "SE"] }
  ]
}

This will result in the following error:

/lmformatenforcer/external/jsonschemaobject.py in validate_exclusive_maximum_and_exclusive_minimum(cls, values)
    175         cls, values: Dict[str, Any]
    176     ) -> Any:
--> 177         exclusive_maximum: Union[float, bool, None] = values.get('exclusiveMaximum')
    178         exclusive_minimum: Union[float, bool, None] = values.get('exclusiveMinimum')
    179 

AttributeError: 'list' object has no attribute 'get'
Chen0x00 commented 9 months ago

It turns out that the version of the specification I was reading is different, prefixItems is works.