-
Notifications
You must be signed in to change notification settings - Fork 35
Make sure we correctly support additionalProperties
set to True
#150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
additionalProperties
is set to True
additionalProperties
set to True
additionalProperties
set to True
additionalProperties
set to True
Okay, so I ran a lot of tests, read the JSON Schema specification, and also looked into this related issue: #149 AFAIU the spec states that having However, the issue that @rlouf pointed out is actually different. Even though the current implementation looks correct, there's still a problem that can be demonstrated with this minimal example: import json
import re
from outlines_core.json_schema import build_regex_from_schema
schema = {
"type": "object",
"properties": {
"a": {
"type": "string",
}
# No need to even mention `additionalProperties`
},
}
regex_str = build_regex_from_schema(json.dumps(schema))
data = json.dumps({
"a": "aaa",
})
print(re.match(regex_str, data))
data = json.dumps({
"a": "aaa",
"id": "1"
})
print(re.match(regex_str, data)) # Shouldn't be `None` The issue with this code is that it doesn't even trigger the line of code mentioned... IIUC the library default behavior is wrong, and that's what need to be changed, not just tweaking |
I think that it makes sense for generation to set the default value to |
@yvan-sraka So And In other words, if you change @rlouf example by dropping
So that's what this bug is about, |
I would also prefer an error that forces the user to set it to |
"Unintuitive" if you know the JSON specification inside and out. We are not using the spec for what it was intended to do (parsing), so we can take small liberties when a default of the original spec doesn't match users' common use cases or mental models. I am yet to meet anyone who complained that |
Setting the
additionalProperties
keyword toTrue
should allow generation of properties whose name is not listed inproperties
, but it is currently not the case:But:
The immediate solution is to return an error when
additionalProperties
is set toTrue
, to avoid surprises. Once that's done we can open an issue to add it to the implementation.The text was updated successfully, but these errors were encountered: