-
Notifications
You must be signed in to change notification settings - Fork 523
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
Fix Infinite Repetition in JSON Schemas Using Integer and String #1154
base: main
Are you sure you want to change the base?
Conversation
25cb1c1
to
db309ef
Compare
return f'"{STRING_INNER}{{{min_length},{max_length}}}"' | ||
|
||
|
||
def build_regex_from_schema( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be at the top. We might also consider separating into multiple modules so it's easier to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I generally like to move helper functions to the end of the file.
cb970c3
to
985dc9c
Compare
@cpfiffer fyi |
985dc9c
to
0f1deee
Compare
…int_pattern / get_str_pattern
0f1deee
to
0f7ecd4
Compare
We might want to hold off on this one actually. I did some profiling on
The better alternative is to
Alternatively we could reduce the size of Let me know if this makes sense |
Overview
The repetition problem of language models combined with patterns allowing for infinite-length fields results in broken JSON Schema outputs.
This was addressed previously for infinite whitespaces issues by setting a safe whitespace pattern as the default. In this PR, the safety of whitespaces is extended to Integer and String patterns.
Behavior
json_schema.to_regex
now includes a kwargsafe_subset=True
.safe_subset=False
r"[\n\t ]*"
safe_subset=True
(default)r"[ ]?"
Fixes
Safe Integer
Safe String
non_strict
mode)Further Work
Important: In the resolved issues, the incorrect outputs are often caused by not applying a chat template. Let's help users get great completions. Examples should include chat templates, or user response quality will suffer. Format
prompts
Using Chat Templates inSequenceGeneratorAdapter
#987Make code more failsafe: Add a non_strict mode to deal with JSONDecodeError errors #985
number
has nosafe_subset
implementation. It's likely the only unsafe primitive remaining without asafe_subset
implementation. However, there aren't any open issues for an error caused by number.