Skip to content

Commit

Permalink
fix pattern-string in json_schema.py by removing anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
lapp0 authored and rlouf committed Jun 22, 2024
1 parent f20c774 commit 60e89f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def to_regex(
elif "pattern" in instance:
pattern = instance["pattern"]
if pattern[0] == "^" and pattern[-1] == "$":
return rf'(^"{pattern[1:-1]}"$)'
return rf'("{pattern[1:-1]}")'
else:
return rf'("{pattern}")'
elif "format" in instance:
Expand Down
4 changes: 3 additions & 1 deletion tests/fsm/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_match_number(pattern, does_match):
# String defined by a regular expression
(
{"title": "Foo", "type": "string", "pattern": r"^[a-z]$"},
r'(^"[a-z]"$)',
r'("[a-z]")',
[('"a"', True), ('"1"', False)],
),
# Boolean
Expand Down Expand Up @@ -749,6 +749,7 @@ def test_match_number(pattern, does_match):
],
)
def test_match(schema, regex, examples):
interegular.parse_pattern(regex)
schema = json.dumps(schema)
test_regex = build_regex_from_schema(schema)
assert test_regex == regex
Expand Down Expand Up @@ -827,6 +828,7 @@ def test_match(schema, regex, examples):
],
)
def test_format(schema, regex, examples):
interegular.parse_pattern(regex)
schema = json.dumps(schema)
test_regex = build_regex_from_schema(schema)
assert test_regex == regex
Expand Down

0 comments on commit 60e89f5

Please sign in to comment.