outlines-dev / outlines

Structured Text Generation
https://outlines-dev.github.io/outlines/
Apache License 2.0
6.94k stars 357 forks source link

Allow escaped strings in `json_schema.py` #991

Closed lapp0 closed 1 week ago

lapp0 commented 1 week ago

Fixes https://github.com/outlines-dev/outlines/issues/935

Problem

On main in json_schema.py,

STRING_INNER = r'([^"\\\x00-\x1f\x7f-\x9f]|\\\\)'

This pattern requires \ to be followed by a second \.

\\ is legal, \" is not.

Solution

Modify the pattern so \\ AND \" are allowed.