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

json_schema.py: If schema has an array with no items key, the pattern is invalid #913

Closed
lapp0 opened this issue May 23, 2024 · 0 comments · Fixed by #919
Closed

json_schema.py: If schema has an array with no items key, the pattern is invalid #913

lapp0 opened this issue May 23, 2024 · 0 comments · Fixed by #919
Labels

Comments

@lapp0
Copy link
Collaborator

lapp0 commented May 23, 2024

Describe the issue as clearly as possible:

In json_schema.py, if the below line is reached, the pattern is illegal.

https://github.com/outlines-dev/outlines/blob/main/outlines/fsm/json_schema.py#L299

In short, there are 5 right-paren, and 4 left-paren

Steps/code to reproduce the bug:

>>> from outlines.fsm.json_schema import build_regex_from_schema
>>> import interegular
>>> pattern = build_regex_from_schema("""{"type": "array"}""")
>>> interegular.parse_pattern(pattern)
Traceback (most recent call last):
  File "/home/andrew/p/outlines/.myenv/lib/python3.11/site-packages/interegular/patterns.py", line 486, in parse
    return super(_ParsePattern, self).parse()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andrew/p/outlines/.myenv/lib/python3.11/site-packages/interegular/utils/simple_parser.py", line 63, in parse
    raise NoMatch(self.data, max(self._expected), self._expected[max(self._expected)])
interegular.utils.simple_parser.NoMatch: Can not match at index 269. Got ')?[\\n', expected any of ['?', '(', '[', '\\', '.', '$', '^', "<Any 1 except ('^', '+', ')', '.', '*', '?', '(', '|', '$', '[', '\\\\')>", '|'].
Context(data[-10:+10]): '\\)*")){0,})?[\\n ]*\\]'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/andrew/p/outlines/.myenv/lib/python3.11/site-packages/interegular/patterns.py", line 730, in parse_pattern
    out = p.parse()
          ^^^^^^^^^
  File "/home/andrew/p/outlines/.myenv/lib/python3.11/site-packages/interegular/utils/simple_parser.py", line 38, in w
    return m(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andrew/p/outlines/.myenv/lib/python3.11/site-packages/interegular/patterns.py", line 488, in parse
    raise InvalidSyntax
interegular.patterns.InvalidSyntax

Expected result:

Successfully compiled pattern

Error message:

No response

Outlines/Python version information:

Version information

``` outlines==6f655ca8f00d6ea42c72eb699d97c78a10a826ab ```

Context for the issue:

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant