noamgat / lm-format-enforcer

Enforce the output format (JSON Schema, Regex etc) of a language model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception when `additionalProperties` is a boolean.

LorrinWWW opened this issue · comments

Boolean value will raise exception:'int' object has no attribute 'get'
Expected behaviours: https://json-schema.org/understanding-json-schema/reference/object#additional-properties

Thanks for the report!
Can you please provide a reproducing example so I can fix it?

When additionalProperties is False, it should be the same to without this field.
For example, given schema:

{
 "type": "object",
 "properties": {
   "number": { "type": "number" },
   "street_name": { "type": "string" },
   "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
 },
 "additionalProperties": false
}

This should be a valid output:

{ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" }

When additionalProperties is True, it allows additional entries with any data types.
if additionalProperties is { "type": <<data_type>> }, it allows additional entries with <<data_type>> data type.
For example, given schema:

{
 "type": "object",
 "properties": {
   "number": { "type": "number" },
   "street_name": { "type": "string" },
   "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
 },
 "additionalProperties": { "type": "string" } 
}

This should be a valid output:

{ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue", "description": "NW"}

where "description" is an additional entry where its corresponding data type could only be "string".

@noamgat Thank you!

@noamgat I am running into this too, I'd really like to be able to pass / enforce "additionalProperties": false