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

Allow escaped strings in json_schema.py #991

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion outlines/fsm/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from referencing._core import Resolver
from referencing.jsonschema import DRAFT202012

STRING_INNER = r'([^"\\\x00-\x1f\x7f-\x9f]|\\\\)'
# allow `\"`, `\\`, or any character which isn't a control sequence
STRING_INNER = r'([^"\\\x00-\x1F\x7F-\x9F]|\\["\\])'
STRING = f'"{STRING_INNER}*"'

INTEGER = r"(-)?(0|[1-9][0-9]*)"
NUMBER = rf"({INTEGER})(\.[0-9]+)?([eE][+-][0-9]+)?"
BOOLEAN = r"(true|false)"
Expand Down
4 changes: 4 additions & 0 deletions tests/fsm/test_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def test_match_number(pattern, does_match):
('"quoted_string"', True),
(r'"escape_\character"', False),
(r'"double_\\escape"', True),
(r'"\n"', False),
(r'"\\n"', True),
(r'"unescaped " quote"', False),
(r'"escaped \" quote"', True),
],
),
# String with maximum length
Expand Down
Loading