Skip to content
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

Inconsistent behavior when compiling a schema with additionalProperties #149

Open
rlouf opened this issue Jan 28, 2025 · 0 comments
Open
Labels
bug Something isn't working json schema

Comments

@rlouf
Copy link
Member

rlouf commented Jan 28, 2025

The behavior of the compiler when additionalProperties is set is inconsistent. For instance the following will not compile:

import json
from outlines_core.fsm.json_schema import build_regex_from_schema


schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "#languagemap",
    "type": "object",
    "patternProperties": {
        "^(yes|no)$": {
        "type": "string"
        }
    },
    "additionalProperties": False
}

regex_str = build_regex_from_schema(json.dumps(schema))
# ValueError: Unsupported JSON Schema structure false 
# Make sure it is valid to the JSON Schema specification and check if it's supported by Outlines.
# If it should be supported, please open an issue.

But it compiles when setting additionalProperties to True:

```python
import json
from outlines_core.fsm.json_schema import build_regex_from_schema


schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "#languagemap",
    "type": "object",
    "patternProperties": {
        "^(yes|no)$": {
        "type": "string"
        }
    },
    "additionalProperties": True
}

regex_str = build_regex_from_schema(json.dumps(schema))

And compiles when additionalProperties is set to False but we replace patternProperties with regular properties:

import json
from outlines_core.fsm.json_schema import build_regex_from_schema


schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "#languagemap",
    "type": "object",
    "properties": {
        "yes": {
        "type": "string"
        }
    },
    "additionalProperties": False
}

regex_str = build_regex_from_schema(json.dumps(schema))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working json schema
Projects
None yet
Development

No branches or pull requests

2 participants