Skip to content

Commit

Permalink
Check the JSON Schema before translating it
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Nov 8, 2023
1 parent 1e64096 commit 8dc0b20
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
- pytest
- pre-commit
- referencing
- jsonschema
- transformers
- pip
- pip:
Expand Down
2 changes: 2 additions & 0 deletions outlines/text/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import re

from jsonschema.protocols import Validator
from referencing import Registry, Resource
from referencing._core import Resolver
from referencing.jsonschema import DRAFT202012
Expand Down Expand Up @@ -37,6 +38,7 @@ def build_regex_from_schema(schema: str):
follows the schema.
"""
Validator.check_schema(schema)
schema = json.loads(schema)

# Build reference resolver
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"numba",
"joblib",
"referencing",
"jsonschema",
]
dynamic = ["version"]

Expand Down Expand Up @@ -86,6 +87,7 @@ exclude=["examples"]
module = [
"jinja2",
"joblib.*",
"jsonschema.*",
"openai",
"numpy.*",
"perscache.*",
Expand Down

0 comments on commit 8dc0b20

Please sign in to comment.